-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayTennis_list.py
More file actions
100 lines (77 loc) · 3.95 KB
/
Copy pathplayTennis_list.py
File metadata and controls
100 lines (77 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Load the dataset
data = {
'Day': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
'Outlook': ['Sunny', 'Overcast', 'Overcast', 'Rain', 'Rain', 'Rain', 'Overcast', 'Overcast', 'Overcast', 'Rain', 'Sunny', 'Overcast', 'Overcast', 'Rain'],
'Temp': ['Hot', 'Hot', 'Hot', 'Mild', 'Cool', 'Cool', 'Cool', 'Mild', 'Cool', 'Mild', 'Mild', 'Mild', 'Hot', 'Mild'],
'Humidity': ['High', 'High', 'High', 'High', 'Normal', 'Normal', 'Normal', 'High', 'Normal', 'Normal', 'Normal', 'High', 'Normal', 'High'],
'Wind': ['Weak', 'Strong', 'Weak', 'Weak', 'Weak', 'Strong', 'Weak', 'Weak', 'Weak', 'Weak', 'Strong', 'Strong', 'Weak', 'Strong'],
'Play': ['No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes', 'No', 'Yes', 'Yes', 'Yes', 'Yes', 'Yes', 'No']
}
df = pd.DataFrame(data)
# One-hot encode categorical variables
df_encoded = pd.get_dummies(df[['Outlook', 'Temp', 'Humidity', 'Wind']])
# Concatenate encoded features with original dataframe
df = pd.concat([df[['Day']], df_encoded, df['Play']], axis=1)
# Split the dataset into features (X) and target variable (Y)
X = df.drop('Play', axis=1)
Y = df['Play']
# Split the dataset into training and testing sets
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)
# Create a logistic regression model
model = LogisticRegression()
# Fit the model to the training data
model.fit(X_train, Y_train)
# Make predictions on the test data
predictions = model.predict(X_test)
# Evaluate the model
accuracy = accuracy_score(Y_test, predictions)
print(f'Accuracy: {accuracy}')
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# Load the dataset
data = {
'Day': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
'Outlook': ['Sunny', 'Overcast', 'Overcast', 'Rain', 'Rain', 'Rain', 'Overcast', 'Overcast', 'Overcast', 'Rain', 'Sunny', 'Overcast', 'Overcast', 'Rain'],
'Temp': ['Hot', 'Hot', 'Hot', 'Mild', 'Cool', 'Cool', 'Cool', 'Mild', 'Cool', 'Mild', 'Mild', 'Mild', 'Hot', 'Mild'],
'Humidity': ['High', 'High', 'High', 'High', 'Normal', 'Normal', 'Normal', 'High', 'Normal', 'Normal', 'Normal', 'High', 'Normal', 'High'],
'Wind': ['Weak', 'Strong', 'Weak', 'Weak', 'Weak', 'Strong', 'Weak', 'Weak', 'Weak', 'Weak', 'Strong', 'Strong', 'Weak', 'Strong'],
'Play': ['No', 'No', 'Yes', 'Yes', 'Yes', 'No', 'Yes', 'No', 'Yes', 'Yes', 'Yes', 'Yes', 'Yes', 'No']
}
df = pd.DataFrame(data)
# One-hot encode categorical variables
df_encoded = pd.get_dummies(df[['Outlook', 'Temp', 'Humidity', 'Wind']])
# Concatenate encoded features with original dataframe
df = pd.concat([df[['Day']], df_encoded, df['Play']], axis=1)
# Split the dataset into features (X) and target variable (Y)
X = df.drop('Play', axis=1)
Y = df['Play']
# Split the dataset into training and testing sets
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2, random_state=42)
# Create a logistic regression model
model = LogisticRegression()
# Fit the model to the training data
model.fit(X_train, Y_train)
# Make predictions on the test data
predictions = model.predict(X_test)
# Evaluate the model
accuracy = accuracy_score(Y_test, predictions)
print(f'Accuracy: {accuracy}')
def interpret_mse(accuracy):
if accuracy < 10:
return "Excellent model accuracy. This is the SHIZ."
elif accuracy < 20:
return "Good model accuracy. A fine auld model."
elif accuracy < 30:
return "Average model accuracy. That'll do pig."
elif accuracy < 40:
return "Below average model accuracy. Don't bet your house on this being true."
else:
return "Poor model accuracy! Get better data or try another fit like polyfit. This shirt ain't linear. \n"
mse_remark = interpret_mse(accuracy)
print(mse_remark)