Skip to content

Instantly share code, notes, and snippets.

@hernamesbarbara
Last active October 20, 2018 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hernamesbarbara/1be94411fc31f0c8569d1288c3ed41bf to your computer and use it in GitHub Desktop.
Save hernamesbarbara/1be94411fc31f0c8569d1288c3ed41bf to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
def make_random_dataframe(ncol, nrow):
"return a random dataframe suitable for simulating a linear regression"
from string import ascii_lowercase as letters
from sklearn.datasets import make_regression
columns = list(letters[:ncol])
X, y = make_regression(n_features=ncol-1, n_samples=nrow, n_targets=1, n_informative=4)
y = y.reshape(X.shape[0], 1)
values = np.hstack((X,y))
return pd.DataFrame(values, columns=columns)
In [202]: df = make_random_dataframe(10, 10)
In [203]: df
Out[203]:
          a         b         c         d         e         f         g  \
0 -0.247312  0.597349  1.620215  2.846240 -1.886408 -0.241958  0.566047
1  0.115897 -1.019171  1.222361  0.110461 -1.892487  1.413497 -1.343769
2  0.370909  0.268609 -0.096972 -0.995053  0.980613 -1.756879 -1.656799
3  0.070093 -0.394620  0.687307  0.065316  0.436284  0.482106  0.192519
4  0.767802  1.590804 -1.023871 -2.294025 -0.202952 -0.957493  0.462735
5  0.090274 -0.618504  0.810471  0.178288  1.125066  0.190667 -0.057684
6  0.480748 -1.002619  1.405576 -1.200686  1.374840 -0.301076 -1.004147
7  1.333150 -0.759525  0.505636 -1.359822 -0.502061  1.247511  0.509366
8  0.619186  1.130353  0.335317 -1.138623  2.667069 -0.609751  0.267005
9 -1.080628 -1.202483 -0.498089 -0.527836  1.168232  0.316020 -0.689657

          h         i           j
0  0.615296 -0.390689   50.141039
1 -0.098790 -1.718524 -255.369575
2  0.215943  0.142025  -90.525565
3 -1.046212  0.617518   68.808623
4 -0.745255  0.206426  -63.473163
5 -0.406074  0.504328   80.346297
6  0.215877 -0.049776  -55.406637
7  0.312341 -0.205337  -58.896879
8  0.353824 -1.397049   -4.060272
9  0.755776 -1.485785 -102.741584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment