Esempio n. 1
0
from sklearn.svm import SVC
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')
Esempio n. 2
0
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

# Lets do some preprocessing...
processor = PreProcessing()
# Encode the data (Country/Gender)
X[:, 1] = processor.encode(X[:, 1])
X[:, 2] = processor.encode(X[:, 2])
X = processor.hot_encoding(data=X, features=[1])
X = X[:, 1:]

# Split the data into training+test
X_train, X_test, y_train, y_test = processor.split(X, y, test_size=0.2)

# Apply feature scaling
X_train = processor.fit_scaler(X_train)
X_test = processor.fit_scaler(X_test)

# Initialize the Artificial Neural Network (ANN)
classifier = Sequential()
# Create the input and first hidden layers
classifier.add(
    Dense(input_dim=11,
          activation='relu',
          units=8,
          kernel_initializer='uniform'))
# Create the second hidden layer
classifier.add(Dense(activation='relu', units=8, kernel_initializer='uniform'))
# Create the output layer
classifier.add(
    Dense(activation='sigmoid', units=1, kernel_initializer='uniform'))