<file_sep># Playing-around-with-Machine-Learning

In this repository some smaller projects will be uploaded. If you would like to make a contribution and have suggestions for improvement, you are welcome
to make a contribution.
The contents are:

1. Linear Regression 
1. K-Means
1. Decision Tree (coming soon)

<file_sep>###########################################################################
###########Playing around with Linear Regression############
###########################################################################

#####Required packages#####

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import RepeatedKFold
from sklearn.model_selection import cross_val_score

#Read in data, explore data, prepare data
df = pd.read_csv(r"hotel_daten.csv")
df = pd.get_dummies(df, columns=["city"])
print(df.dtypes)
print(df.describe())
print(df.nunique())
print(df.corr())


#Evaluating some linear regression with Repeated K-Fold Cross-Validation
'''Model 1'''
X = df[["profit", "square meter"]].values
y = df[["price in millions"]].values

score = cross_val_score(LinearRegression(), X, y, cv=RepeatedKFold(n_repeats=200))
print(np.mean(score))

'''Model 2'''
X = df[["profit", "square meter", "city_Berlin", "city_Köln"]].values
y = df[["price in millions"]].values

score = cross_val_score(LinearRegression(), X, y, cv=RepeatedKFold(n_repeats=200))
print(np.mean(score))

'''Model 3'''
X = df[["square meter", "city_Berlin", "city_Köln"]].values
y = df[["price in millions"]].values

score = cross_val_score(LinearRegression(), X, y, cv=RepeatedKFold(n_repeats=200))
print(np.mean(score))

'''Model 4'''
X = df[["square meter"]].values
y = df[["price in millions"]].values
score = cross_val_score(LinearRegression(), X, y, cv=RepeatedKFold(n_repeats=200))
print(np.mean(score))

#Single parameter "square meter" seems to explain the price of asset very well on its own

single_model = LinearRegression().fit(X,y)
x_min = min(X)
x_max = max(X)
predicted = single_model.predict([x_min,x_max])
plt.scatter(X, y, color="b")
plt.plot([x_min,x_max], predicted, color="r")
plt.title(" Simple Regression ")
plt.ylabel("Price of asset in millions")
plt.xlabel("Total square meters of building")
plt.legend(loc="upper left", labels=["Regression line", "True values"])
plt.show()
