I can not get this program to work. import numpy as np import pandas as pd # Do not change these options; This allows the CodeGrade auto grading to function correctly pd.set_option('display.max_columns', None) import warnings warnings.filterwarnings('ignore') fileName = "JohnnyPiesData.csv" pie_df = pd.read_csv('JohnnyPiesData.csv') pie_df pie_df =pie_df.drop(['Example'],axis=1); features = pie_df.drop(['Example'], axis = 1); response = pd.get_dummies(pie_df['Example']) pie_df from sklearn.linear_model import LinearRegression from sklearn.metrics import accuracy_score reg_model = LinearRegression() reg_model.fit(features, response) reg_model.coef_ reg_model.intercept_ preds = reg_model.predict (features) preds [preds <= 0.5] = 0 preds[preds > 0.5] = 1 resp_comp = response.copy() reg_outputs = [float(reg_model.predict(np.reshape(row, (1, -1)))) for row in features.itertuples(index=False)] predicted_resp = np.array([1 if reg_output > 0.5 else 0 for reg_output in reg_outputs]) resp_comp = resp_comp.assign(Regression_Predictions = reg_outputs) resp_comp = resp_comp.assign(Predicted_Responses = predicted_resp) resp_comp acc_score = accuracy_score(response, preds)
I can not get this program to work.
import numpy as np
import pandas as pd
# Do not change these options; This allows the CodeGrade auto grading to function correctly
pd.set_option('display.max_columns', None)
import warnings
warnings.filterwarnings('ignore')
fileName = "JohnnyPiesData.csv"
pie_df = pd.read_csv('JohnnyPiesData.csv')
pie_df
pie_df =pie_df.drop(['Example'],axis=1);
features = pie_df.drop(['Example'], axis = 1);
response = pd.get_dummies(pie_df['Example'])
pie_df
from sklearn.linear_model import LinearRegression
from sklearn.metrics import accuracy_score
reg_model = LinearRegression()
reg_model.fit(features, response)
reg_model.coef_
reg_model.intercept_
preds = reg_model.predict (features)
preds [preds <= 0.5] = 0
preds[preds > 0.5] = 1
resp_comp = response.copy()
reg_outputs = [float(reg_model.predict(np.reshape(row, (1, -1)))) for row in features.itertuples(index=False)]
predicted_resp = np.array([1 if reg_output > 0.5 else 0 for reg_output in reg_outputs])
resp_comp = resp_comp.assign(Regression_Predictions = reg_outputs)
resp_comp = resp_comp.assign(Predicted_Responses = predicted_resp)
resp_comp
acc_score = accuracy_score(response, preds)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps