I need to produce a row for the confidence interval for every field that I am calculating coefficients and scores off of. So here is my code so far-

import pandas as pd
import numpy as np
from sklearn.linear_model import ElasticNet
from sklearn.model_selection import GridSearchCV

lr = ElasticNet(max_iter=50000)
parameters = {'fit_intercept': [False],
              'l1_ratio': [x/10 for x in range(2, 10)], 
              'selection': ['random', 'cyclic'], 
              'alpha': [x/10 for x in range(5, 10)], 

df = {
      'Field':[], 'A': [], 
      'b': [], 'Score': [], 
      'Row_Counts': [], 'Average_Spend': []
dupes = []
for field in all_df['Field']:
    if field not in dupes:
        filt = all_df[all_df['Field'] == field]
        filt = filt[filt['LFA\'s'] != 0]
        filt['root_Spend'] = np.sqrt(filt['Spend'])
        filt.replace(-np.inf, 0, inplace=True)
        X = filt[['Spend', 'root_Spend', 'CL', 'V']]
        y = filt['LFA\'s']
        if len(X) >= 5:
            gs = GridSearchCV(lr, parameters, cv=5, scoring='neg_mean_squared_error', n_jobs=10, error_score='ignore', verbose=1)
            gs.fit(X, y)
            df['Score'].append(gs.best_estimator_.score(X, y))

I need to make df have a column for confidence intervals as well. Any ideas/answers?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.