-
Notifications
You must be signed in to change notification settings - Fork 0
/
sale_prediction_age_salary_prediction_logistic_regression
35 lines (34 loc) · 1.45 KB
/
sale_prediction_age_salary_prediction_logistic_regression
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
import pandas as pd #import pandas library
import numpy as np # import numpy library
dataset = pd.read_csv("DigitalAd_dataset.csv") # read the dataset
print(dataset.shape) #print the dataset size
print(dataset.head(400)) # print the dataset headers
X = dataset.iloc[:,:-1].values #separating the dataset
X
Y = dataset.iloc[:,-1].values
Y
from sklearn.model_selection import train_test_split #training the model
X_train,X_test,y_train,y_test = train_test_split(X,Y,test_size=0.25,random_state = 0)
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.fit_transform(X_test)
from sklearn.linear_model import LogisticRegression #import logistic regression library
model = LogisticRegression(random_state = 0)
model.fit(X_train,y_train)
age = int(input("Enter new customer age:")) #prediction whether customer of age and salary will buy the product
salary = int(input("Enter new customer salary:"))
newCust = [[age,salary]]
result = model.predict(sc.transform(newCust))
print(result)
if result == 1:
print("Wohoo! Customer will buy!")
else:
print("Nah! Customer will not buy!")
y_pred = model.predict(X_test)
print(np.concatenate((y_pred.reshape(len(y_pred),1),y_test.reshape(len(y_test),1)),1))
from sklearn.metrics import confusion_matrix,accuracy_score
cm = confusion_matrix(y_test,y_pred)
print("Confusion__matrix:")
print(cm)
print("Accuracy of the model: {0}.".format(accuracy_score(y_test,y_pred*100)))