How to use 'pandas sample datasets' in Python

Every line of 'pandas sample datasets' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
143def random_undersampling(dataset):
144 minority_set = dataset[dataset.Trend == -1.0]
145 majority_set = dataset[dataset.Trend == 1.0]
146
147 # print(dataset.Trend.value_counts())
148
149 # If minority set larger than majority set, swap
150 if len(minority_set) > len(majority_set):
151 minority_set, majority_set = majority_set, minority_set
152
153 # Downsample majority class
154 majority_downsampled = resample(majority_set,
155 replace=False, # sample without replacement
156 n_samples=len(minority_set), # to match minority class
157 random_state=123) # reproducible results
158
159 # Combine minority class with downsampled majority class
160 return pd.concat([majority_downsampled, minority_set])

Related snippets