import sys
sys.path.append('C:/Users/akhram/Desktop/AIML/Machine Learning/Utils')

import classification_utils as cutils
from sklearn import model_selection

#2-d classification pattern
X, y = cutils.generate_linear_synthetic_data_classification(n_samples=500,
                                                            n_features=2,
                                                            n_classes=2,
                                                            weights=[0.4, 0.6],
                                                            class_sep=1)
cutils.plot_data_2d_classification(X, y)

X, y = cutils.generate_linear_synthetic_data_classification(
    n_samples=500,
    n_features=3,
    n_classes=3,
    weights=[0.4, 0.3, 0.3],
    class_sep=1)
cutils.plot_data_3d_classification(X, y)

X_train, X_test, y_train, y_test = model_selection.train_test_split(
    X, y, test_size=0.2, random_state=1)
cutils.plot_data_2d_classification(X_train, y_train)
Esempio n. 2
0
import sys
sys.path.append("E:/utils")

import classification_utils as cutils
from sklearn import preprocessing
import numpy as np

X, y = cutils.generate_nonlinear_synthetic_data_classification2(n_samples=1000,
                                                                noise=0.1)
X, y = cutils.generate_nonlinear_synthetic_data_classification3(n_samples=1000,
                                                                noise=0.1)

cutils.plot_data_2d_classification(X, y)

#guassian basis transformation
tmp = np.exp(-(X**2).sum(1))
X_3d = np.c_[X, tmp]
cutils.plot_data_3d_classification(
    X_3d,
    y,
    new_window=True,
    title="Linearly separable data in 3D with basis change")

#polynomial basis transformation
poly_features = preprocessing.PolynomialFeatures()
X_poly1 = poly_features.fit_transform(X)

poly_features = preprocessing.PolynomialFeatures(degree=3)
X_poly2 = poly_features.fit_transform(X)
import pandas as pd
import os

#2-d classification pattern
X, y = cutils.generate_linear_synthetic_data_classification(n_samples=1000, n_features=2, n_classes=4, weights=[0.3,0.3,0.2,0.2])
cutils.plot_data_2d_classification(X, y)

X, y = cutils.generate_nonlinear_synthetic_data_classification1(n_samples=1000, n_features=2, n_classes=2)
cutils.plot_data_2d_classification(X, y)

X, y = cutils.generate_nonlinear_synthetic_data_classification2(n_samples=1000, noise=0.05)
cutils.plot_data_2d_classification(X, y)

X, y = cutils.generate_nonlinear_synthetic_data_classification3(n_samples=1000, noise=0.05)
cutils.plot_data_2d_classification(X, y)

#3-d classification pattern
X, y = cutils.generate_linear_synthetic_data_classification(n_samples=1000, n_features=3, n_classes=5, weights=list(np.repeat(0.1,5)))
cutils.plot_data_3d_classification(X, y)

X, y = cutils.generate_nonlinear_synthetic_data_classification1(n_samples=1000, n_features=3, n_classes=2)
cutils.plot_data_3d_classification(X, y)

dir = 'E:/'
titanic_train = pd.read_csv(os.path.join(dir, 'train.csv'))
print(titanic_train.info())
features = ['Pclass', 'Fare', 'SibSp']
X_train = titanic_train[features]
y_train = titanic_train['Survived']
cutils.plot_data_3d_classification(X_train, y_train)