Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random as r
- import numpy as np
- import pandas as pd
- import statsmodels as smf
- j = 0
- #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.#
- while j < ((Dataframe.shape[1])*(Dataframe.shape[1]-1)*(Dataframe.shape[1]-2)*(Dataframe.shape[1]-3)*(Dataframe.shape[1]-4)):
- #Below our dependent variable X, which is randomized from the dataframe#
- X = Dataframe.iloc[:, r.sample(range(4,Dataframe.shape[1]),5)]
- #Below our model, a classic OLS with constant#
- sm.add_constant(X , prepend=True )
- Model = smf.OLS(Y, X)
- #Below the results for a single regression#
- Results = Model.fit()
- #The Results parameters type is "Pandas.Core.Series.Series",
- therefore I have transformed the values within Results.params into a
- Database#
- Parameters = pd.DataFrame(Results.params).reset_index()
- Parameters.columns = ['names', 'values']
- #Below you will see our database, named as DB_Parameters, right now
- #it's nothing but a repository for all the 47 coefficient names to be in place.#
- DB_Parameters = pd.DataFrame(np.unique(np.append(DB_Parameters, Parameters.iloc[:,0])))
- DB_Parameters.columns = ['names']
- if all((Parameters['names']).isin(Databank.iloc[:,0])):
- #Here i want start to populate the database with the regression parameters#
- print(DB_Parameters):
- names params
- const 0.04
- B_1 0.05
- B_2 0.03
- B_3 NaN
- B_4 NaN
- B_5 0.96
- const = 0.04
- B_1 = 0.05
- const = 0.06
- B_1 = 0.12
- name iteration1 iteration2 .... ..... ....
- const 0.04 0.06
- B_1 0.05 0.015
- B_2 0.03 "Eventually, another value, if extracted"
- B_3 NaN "Eventually, another value, if extracted"
- ... ... NaN
Add Comment
Please, Sign In to add comment