Guest User

Untitled

a guest
May 17th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import random as r
  2. import numpy as np
  3. import pandas as pd
  4. import statsmodels as smf
  5.  
  6. j = 0
  7. #Here below i'm just saying that j has to be lower then n*(n-1)*(n-2)*(n-3)*(n-4), which is the amount of combinations that you can find by extracting 5 different coefficients from a n columns database.#
  8.  
  9. while j < ((Dataframe.shape[1])*(Dataframe.shape[1]-1)*(Dataframe.shape[1]-2)*(Dataframe.shape[1]-3)*(Dataframe.shape[1]-4)):
  10.  
  11. #Below our dependent variable X, which is randomized from the dataframe#
  12.  
  13. X = Dataframe.iloc[:, r.sample(range(4,Dataframe.shape[1]),5)]
  14. #Below our model, a classic OLS with constant#
  15. sm.add_constant(X , prepend=True )
  16. Model = smf.OLS(Y, X)
  17. #Below the results for a single regression#
  18. Results = Model.fit()
  19.  
  20. #The Results parameters type is "Pandas.Core.Series.Series",
  21. therefore I have transformed the values within Results.params into a
  22. Database#
  23.  
  24. Parameters = pd.DataFrame(Results.params).reset_index()
  25. Parameters.columns = ['names', 'values']
  26.  
  27. #Below you will see our database, named as DB_Parameters, right now
  28. #it's nothing but a repository for all the 47 coefficient names to be in place.#
  29.  
  30. DB_Parameters = pd.DataFrame(np.unique(np.append(DB_Parameters, Parameters.iloc[:,0])))
  31. DB_Parameters.columns = ['names']
  32.  
  33. if all((Parameters['names']).isin(Databank.iloc[:,0])):
  34.  
  35. #Here i want start to populate the database with the regression parameters#
  36.  
  37. print(DB_Parameters):
  38. names params
  39. const 0.04
  40. B_1 0.05
  41. B_2 0.03
  42. B_3 NaN
  43. B_4 NaN
  44. B_5 0.96
  45.  
  46. const = 0.04
  47. B_1 = 0.05
  48.  
  49. const = 0.06
  50. B_1 = 0.12
  51.  
  52. name iteration1 iteration2 .... ..... ....
  53. const 0.04 0.06
  54. B_1 0.05 0.015
  55. B_2 0.03 "Eventually, another value, if extracted"
  56. B_3 NaN "Eventually, another value, if extracted"
  57. ... ... NaN
Add Comment
Please, Sign In to add comment