# Defines Logistic Regression Model:
model = LogisticRegression()

# Trains the model
model.fit(XTrain, yTrain)
yPredicted = model.predict(XTest)

print("Die Vorhersagegenauigkeit entspricht: ")
print(100 * model.score(XTest, yTest), "%")

# Prints diagram of the real test Data:
plt.scatter(XTest[:, 0], XTest[:, 1], c=yTest)
plt.xlabel("Number of Sport activities per month")
plt.ylabel("Number of eating healthy per month")
plt.title("REAL TEST DATA")
plt.show()

# Prints diagram of the Prediction:
plt.scatter(XTest[:, 0], XTest[:, 1], c=yPredicted)
plt.xlabel("Number of Sport activities per month")
plt.ylabel("Number of eating healthy per month")
plt.title("PREDICTED DATA")
plt.show()

# Prints diagramm of the real test Data with seperator
plot_classifier(model,
                XTest,
                yTest,
                proba=True,
                xlabel="Number of Sport activities per month",
                ylabel="Number of eating healthy per month")
X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    random_state=0,
                                                    test_size=0.25)

scaler = StandardScaler()
scaler.fit(X_train)

X_train = scaler.transform(X_train)
X_test = scaler.transform(X_test)

model = SVC(kernel="poly", degree=2, coef0=1, C=1)
model.fit(X_train, y_train)

print(model.score(X_test, y_test))

# Trainings-Daten plotten
plot_classifier(model,
                X_train,
                y_train,
                proba=False,
                xlabel="Alter",
                ylabel="Interesse")

# Testdaten plotten
plot_classifier(model,
                X_test,
                y_test,
                proba=False,
                xlabel="Alter",
                ylabel="Interesse")
Ejemplo n.º 3
0
import pandas as pd
import graphviz
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from helper import plot_classifier

df = pd.read_csv("classification.csv")

y = df["success"].values
X = df[["age", "interest"]].values

X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    random_state=0,
                                                    test_size=0.25)

model = RandomForestClassifier(criterion="entropy",
                               n_estimators=100)  # Anzahl der Bäume im Wald
model.fit(X_train, y_train)

plot_classifier(model,
                X_train,
                y_train,
                proba=True,
                xlabel="Alter",
                ylabel="Interesse")

print(model.score(X_test, y_test))
Ejemplo n.º 4
0
                                                    random_state=0,
                                                    test_size=0.4)

from sklearn.neighbors import KNeighborsClassifier

model = KNeighborsClassifier()
model.fit(X_train, y_train)

print(model.score(X_test, y_test))

from helper import plot_classifier

# train data plot
plot_classifier(model,
                X_train,
                y_train,
                proba=False,
                xlabel="feature",
                ylabel="label")

# test data plot
plot_classifier(model,
                X_test,
                y_test,
                proba=False,
                xlabel="feature",
                ylabel="label")

#Task 4 varitity of classifiers
###############################################################################
import os
os.chdir("./")
Ejemplo n.º 5
0
Y = DF["desease"].values

# Splitting the Set in Train and Test Data:
XTRAIN, XTEST, YTRAIN, YTEST = train_test_split(X,
                                                Y,
                                                random_state=0,
                                                test_size=0.25)

# creates a random forest with a maximum node-depth of 4
# and a minumum number of 3 examples per leaf
MODEL = RandomForestClassifier(criterion="gini",
                               max_depth=4,
                               min_samples_leaf=3)

MODEL = MODEL.fit(XTEST, YTEST)
print(MODEL.score(XTEST, YTEST))

plot_classifier(MODEL,
                XTRAIN,
                YTRAIN,
                proba=True,
                xlabel="monthlySport",
                ylabel="monthlyHealthyFood")

plot_classifier(MODEL,
                XTEST,
                YTEST,
                proba=True,
                xlabel="monthlySport",
                ylabel="monthlyHealthyFood")