Example #1
0
from sklearn.metrics import confusion_matrix

# Import data
dataset = LoadData("Social_Network_Ads.csv").data

# Split the dataset
X = dataset.iloc[:, [2,3]].values
y = dataset.iloc[:, 4].values

# Lets do some preprocessing...
processor = PreProcessing()
# Split the data
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.25)
# scale the data
X_train = processor.fit_scaler(X_train)
X_test = processor.scale(X_test)

# Lets fit the model now
classifier = SVC(kernel='rbf', random_state=0)
classifier.fit(X_train, y_train)

# Predict!
y_pred = classifier.predict(X_test)

# Creating the confusion matrix
cm = confusion_matrix(y_test, y_pred)
cm
# Fine, lets visualize it.. I geuss its more fun ­ЪциРђЇ
visual = ClassifierVisual(X_train, y_train, classifier)
visual.visualize(title='Linear SVM', xlab='Age', ylab='Salary')
Example #2
0
# Import data
dataset = LoadData("Social_Network_Ads.csv").data

# Split the dataset
X = dataset.iloc[:, [2, 3]].values
y = dataset.iloc[:, 4].values

# Lets do some preprocessing...
processor = PreProcessing()
# Split the data
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.25)
# scale the data
X_train = processor.fit_scaler(X_train)
X_test = processor.scale(X_test)

# Lets fit the model now
classifier = RandomForestClassifier(n_estimators=10,
                                    criterion='entropy',
                                    random_state=0)
classifier.fit(X_train, y_train)

# Predict!
y_pred = classifier.predict(X_test)

# Creating the confusion matrix
cm = confusion_matrix(y_test, y_pred)
cm
# Fine, lets visualize it.. I geuss its more fun ­ЪциРђЇ
visual = ClassifierVisual(X_test, y_test, classifier)
visual.visualize(title='Decision Tree', xlab='Age', ylab='Salary')
Example #3
0
from sklearn.metrics import confusion_matrix

# Import data
dataset = LoadData("Social_Network_Ads.csv").data

# Split the dataset
X = dataset.iloc[:, [2,3]].values
y = dataset.iloc[:, 4].values

# Lets do some preprocessing...
processor = PreProcessing()
# Split the data
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.25)
# scale the data
X_train = processor.fit_scaler(X_train)
X_test = processor.scale(X_test)

# Lets fit the model now
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)

# Predict!
y_pred = classifier.predict(X_test)

# Creating the confusion matrix
cm = confusion_matrix(y_test, y_pred)

# Fine, lets visualize it.. I geuss its more fun ­ЪциРђЇ
visual = ClassifierVisual(X_test, y_test, classifier)
visual.visualize(title='Logistic Regression', xlab='Age', ylab='Salary')
Example #4
0
X = dataset.iloc[:, 0:13].values
y = dataset.iloc[:, 13].values

# Lets do some preprocessing...
processor = PreProcessing()
# Split the data
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.2)
# scale the data
X_train = processor.fit_scaler(X_train)
X_test = processor.scale(X_test)

# Apply PCA
pca = PCA(n_components = 2)
X_train = pca.fit_transform(X_train)
X_test = pca.transform(X_test)
explained_variance = pca.explained_variance_ratio_

# Lets fit the model now
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train, y_train)

# Predict!
y_pred = classifier.predict(X_test)

# Creating the confusion matrix
cm = confusion_matrix(y_test, y_pred)

# Fine, lets visualize it.. I geuss its more fun ­ЪциРђЇ
visual = ClassifierVisual(X_train, y_train, classifier)
visual.visualize(title='Logistic Regression', xlab='Age', ylab='Salary', colors=('red', 'green', 'blue'))
Example #5
0
from sklearn.metrics import confusion_matrix

# Import data
dataset = LoadData("Social_Network_Ads.csv").data

# Split the dataset
X = dataset.iloc[:, [2,3]].values
y = dataset.iloc[:, 4].values

# Lets do some preprocessing...
processor = PreProcessing()
# Split the data
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.25)
# scale the data
X_train = processor.fit_scaler(X_train)
X_test = processor.scale(X_test)

# Lets fit the model now
classifier = KNeighborsClassifier(n_neighbors=5, metric='minkowski', p=2)
classifier.fit(X_train, y_train)

# Predict!
y_pred = classifier.predict(X_test)

# Creating the confusion matrix
cm = confusion_matrix(y_test, y_pred)
cm
# Fine, lets visualize it.. I geuss its more fun ­ЪциРђЇ
visual = ClassifierVisual(X_test, y_test, classifier)
visual.visualize(title='K Nearest Neighbor', xlab='Age', ylab='Salary')