<jupyter_start><jupyter_text>Basics of machine learning  ImportsEssential import for this tutorial which will use in different part of tutorial<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from sklearn.metrics import mean_absolute_error
from sklearn.metrics import mean_squared_error
from sklearn.metrics import explained_variance_score


from sklearn import datasets

from sklearn import linear_model
from sklearn import svm
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.cluster import KMeans
from sklearn.neighbors import KNeighborsClassifier<jupyter_output><empty_output><jupyter_text>Error mesurment in sklearn<jupyter_code># import numpy as np
# from sklearn.metrics import mean_absolute_error
# from sklearn.metrics import mean_squared_error
# from sklearn.metrics import explained_variance_score

actual = np.array([1,2,3,4])
predect = np.array([1.2,2.1,3.3,4.1])
mae = mean_absolute_error(actual, predect)
mse = mean_squared_error(actual, predect)

var = explained_variance_score(actual, predect)
print("Mean Abs Error : ", mae)
print("Mean Sqr Error : ", mse)
print("Mean Var Error : ", var)<jupyter_output>Mean Abs Error :  0.17499999999999988
Mean Sqr Error :  0.03749999999999996
Mean Var Error :  0.9945<jupyter_text>Dataset PriprationWe are using sklearn iris dataset<jupyter_code># import pandas as pd
# from sklearn import datasets

iris_set = datasets.load_iris()
print("Iris set count:", len(iris_set))
data = pd.DataFrame(iris_set.data[:,0:4])
data.columns = ['a', 'b', 'c', 'd']
target = pd.DataFrame(iris_set.target)
target.columns = ['e']

print("Data shape:", data.shape)
print("target shape:", target.shape)

#'target_names': array(['setosa', 'versicolor', 'virginica'],<jupyter_output>Iris set count: 6
Data shape: (150, 4)
target shape: (150, 1)<jupyter_text>Linear RegressionLinear Regression model<jupyter_code># from sklearn import linear_model

model = linear_model.LinearRegression()
reg = model.fit(data, target)
predict = model.predict([[1,1,1,1]])
print(predict) 
# 0.87 near to 1
print(model.coef_)<jupyter_output>[[0.87240699]]
[[-0.11190585 -0.04007949  0.22864503  0.60925205]]<jupyter_text>Logistic RegrationLogistic Regration Used in classification problem (binary or multi)<jupyter_code># from sklearn import linear_model

model = linear_model.LogisticRegression()
reg = model.fit(data, target)
predict = model.predict([[0,1,2,2]])
print(predict) 
print(model.coef_)
from sklearn import svm

# SVM
svc = svm.SVC(kernel='linear', C=0.05).fit(data, target)
reg = svc.fit(data, target)
predict = reg.predict([[0,1,2,2]])
print("Priciction: ", predict)
from sklearn.tree import DecisionTreeClassifier

#Desission Tree
model = DecisionTreeClassifier(criterion='entropy')
reg = model.fit(data, target)
predict = model.predict([[1,1,1,1]])
print(predict)
from sklearn.ensemble import RandomForestClassifier

#Random Forest
model = RandomForestClassifier()
reg = model.fit(data, target)
predict = model.predict([[1,1,1,1]])
print(predict)
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans

# In[]
#K Mean cluster

colormap = np.array(['blue', 'red', 'black'])
plt.scatter(data.a, data.b, c=colormap[target.e])
plt.title('Data')
plt.show()

model = KMeans(n_clusters=3, random_state=5).fit(target)
predict = model.predict
print(predict)
label = model.labels_
print(label)
cluster_center = model.cluster_centers_
print(cluster_center)
plt.polar(cluster_center, '--or')
plt.show()
from sklearn.neighbors import KNeighborsClassifier

#KNeighbors Classifier
model = KNeighborsClassifier()
reg = model.fit(data, target)
predict = model.predict([[1,1,1,1]])
print(predict)<jupyter_output>[0]
{'fraction_non_alphanumeric': 0.12002138465650895, 'fraction_numerical': 0.03822507350975675, 'mean_word_length': 7.012847965738758, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '372274', 'license': 'MIT', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1301, 'n_words': 315, 'path': 'Scikit-learn/sklearn.ipynb', 'repo_name': 'Krprashant94/Machine-Learning-Basic', 'size': '3741'}