Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
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)


What I have tried:

Python
pie_df =pie_df.drop(['Example'],axis=1);
features = pie_df.drop(['Example'], axis =  1); 
response = pd.get_dummies(pie_df['Example'])
pie_df
Posted
Updated 9-Sep-22 4:12am
v3
Comments
Richard MacCutchan 9-Sep-22 9:25am    
It is not clear exactly what problem you are trying to overcome. Please use the Improve question link above, and add complete details of what is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900