Skip to content

Commit a088209

Browse files
authored
Add files via upload
1 parent a0ed1ae commit a088209

File tree

2 files changed

+448
-0
lines changed

2 files changed

+448
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Wed Dec 19 17:30:09 2018
5+
6+
@author: omairaasim
7+
"""
8+
9+
# Step 1 - Load Data
10+
import pandas as pd
11+
dataset = pd.read_csv("iphone_purchase_records.csv")
12+
X = dataset.iloc[:,:-1].values
13+
y = dataset.iloc[:, 3].values
14+
15+
# Step 2 - Convert Gender to number
16+
from sklearn.preprocessing import LabelEncoder
17+
labelEncoder_gender = LabelEncoder()
18+
X[:,0] = labelEncoder_gender.fit_transform(X[:,0])
19+
20+
21+
# Step 3 - Feature Scaling
22+
from sklearn.preprocessing import StandardScaler
23+
sc = StandardScaler()
24+
X = sc.fit_transform(X)
25+
26+
# Step 4 - Compare Classification Algorithms
27+
from sklearn.model_selection import KFold
28+
from sklearn.model_selection import cross_val_score
29+
from sklearn.linear_model import LogisticRegression
30+
from sklearn.tree import DecisionTreeClassifier
31+
from sklearn.neighbors import KNeighborsClassifier
32+
from sklearn.ensemble import RandomForestClassifier
33+
from sklearn.naive_bayes import GaussianNB
34+
from sklearn.svm import SVC
35+
36+
classification_models = []
37+
classification_models.append(('Logistic Regression', LogisticRegression(solver="liblinear")))
38+
classification_models.append(('K Nearest Neighbor', KNeighborsClassifier(n_neighbors=5, metric="minkowski",p=2)))
39+
classification_models.append(('Kernel SVM', SVC(kernel = 'rbf',gamma='scale')))
40+
classification_models.append(('Naive Bayes', GaussianNB()))
41+
classification_models.append(('Decision Tree', DecisionTreeClassifier(criterion = "entropy")))
42+
classification_models.append(('Random Forest', RandomForestClassifier(n_estimators=100, criterion="entropy")))
43+
44+
for name, model in classification_models:
45+
kfold = KFold(n_splits=10, random_state=7)
46+
result = cross_val_score(model, X, y, cv=kfold, scoring='accuracy')
47+
print("%s: Mean Accuracy = %.2f%% - SD Accuracy = %.2f%%" % (name, result.mean()*100, result.std()*100))

0 commit comments

Comments
 (0)