res = mod.fit(maxiter=1000, disp=False) print(res.summary()) res.forecast(steps=1) fcast_res1 = res.get_forecast(steps=1) # Most results are collected in the `summary_frame` attribute. print(fcast_res1.summary_frame(4)) import statsmodels.api as sm X=df.iloc[:, 1:38] y=df.iloc[:, 38] model=sm.OLS(y,X).fit() predictions=model.predict(X) model.summary() predictions pd.concat([y,predictions], axis=1) #Ordinal Brier score for 5 bin questions #forecast f=[0.2, 0.2, 0.2, 0.2, 0.2] #actual a=[1,0,0,0,0] def ord_brier(forecast, actual): #find squared error of each cumulative group of bins bin1cumulativeerror=(sum(forecast[:1])-sum(actual[:1]))**2
model.fit(X_train, y_train) # get coefficients print('Intercept:', model.intercept_) print('Slope:', model.coef_) print( pd.DataFrame({ 'Variable': ['intercept'] + list(X.columns), 'Coefficient': [ "{0:.5f}".format(v) for v in np.append( model.intercept_, model.coef_.flatten()).round(6) ] })) # get fitted value on training set y_train_predicted = model.predict(X_train) # compare predictions print( pd.DataFrame({ 'True': y_train.ravel(), 'Predicted': y_train_predicted.ravel() })) # deleting outliers Q1 = df_linreg.quantile(0.2) Q3 = df_linreg.quantile(0.8) IQR = Q3 - Q1 dataset_outlier = df_linreg[~((df_linreg < (Q1 - IQR)) | (df_linreg >