Skip to content

Commit

Permalink
Classification SVM model of ozone Machine Learning
Browse files Browse the repository at this point in the history
I developed 2 machine learning software that predict and classify ozone day and non-ozone day. The working principle of the two is similar but there are differences. I got the dataset from ics.icu. Each software has a different mathematical model, Gaussian RBF and Linear Kernel, and classifications are visualized in different ways. I would be happy to present the software to you!
  • Loading branch information
emirhanai authored Sep 6, 2021
1 parent 9d79431 commit 16323ca
Show file tree
Hide file tree
Showing 7 changed files with 2,713 additions and 2 deletions.
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# Classification-thanks-to-the-SVM-model-with-7-years-of-ozone-data-with-Machine-Learning
I developed 2 machine learning software that predict and classify ozone day and non-ozone day. The working principle of the two is similar but there are differences. I got the dataset from ics.icu. Each software has a different mathematical model, Gaussian RBF and Linear Kernel, and classifications are visualized in different ways. I would be happy to present the software to you!
# **Classification thanks to the SVM model with 7 years of ozone data with Machine Learning**
I developed 2 machine learning software that predict and classify ozone day and non-ozone day. The working principle of the two is similar but there are differences. I got the dataset from ics.icu. Each software has a different mathematical model, Gaussian RBF and Linear Kernel, and classifications are visualized in different ways. I would be happy to present the software to you!

_Example:_ `model_ozone = PCA(n_components=72).fit(X_train)`

`model = svm.SVC(kernel='rbf', gamma=0.05, C=3)`

`model_ozone = svm.SVC(kernel='linear', C=3)

**I am happy to present this software to you!**

Data Source: [DataSource]
###**The coding language used:**

`Python 3.9.6`

###**Libraries Used:**

`Sklearn`

`Pandas`

`Numpy`

`Pylab`

`Matplotlib`
### **Developer Information:**

Name-Surname: **Emirhan BULUT**

Contact (Email) : **emirhan.bulut@turkiyeyapayzeka.com**

LinkedIn : **[https://www.linkedin.com/in/artificialintelligencebulut/][LinkedinAccount]**

[LinkedinAccount]: https://www.linkedin.com/in/artificialintelligencebulut/

Official Website: **[https://www.emirhanbulut.com.tr][OfficialWebSite]**

[OfficialWebSite]: https://www.emirhanbulut.com.tr

[DataSource]: https://archive.ics.uci.edu/ml/index.php
2,535 changes: 2,535 additions & 0 deletions ozone-data.csv

Large diffs are not rendered by default.

Binary file added ozone-normal-day-classification-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ozone-normal-day-classification-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ozone-normal-day-classification-WSR0-WSR1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions svm-ozone-linear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from sklearn import svm
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn import metrics
import pandas as pd
#from sklearn.preprocessing import LabelEncoder

df = pd.read_csv('ozone-data.csv')
#print(df.head())

#data select
X = df.iloc[:,1:73]
#print(X)

#target select [class]
y = df.iloc[:,73:74]
#print(y)

#dataframe to numpy array
yyy = np.array(y).ravel()
XXX = np.array(X).reshape(2534,-1)
#print(target)
#print(connects)

#target_variables = LabelEncoder()

#y['Date_data'] = target_variables.fit_transform(y['Date'])

#y_n = y.drop(['Date'],axis=1)

#print("Features: ", X)

#print("Target: ", y_n)

X_train, X_test, y_train, y_test = train_test_split(XXX,yyy,test_size=0.2880820836621942,random_state=49) # 80% training and 20% test

#creating of SVM model
model_ozone = svm.SVC(kernel='linear', C=3) # Linear Kernel

#Train the model using the training sets
model_ozone.fit(X_train, y_train)

#Predict the response for test dataset
y_test_pred = model_ozone.predict(X_test)
#print(X_test)
#print(y_test)
#Accuracy

#C = 1.0

#h = .02

#rbf_svc = svm.SVC(kernel='rbf', gamma=0.7, C=C).fit(X_train, y_train)
#poly_svc = svm.SVC(kernel='poly', degree=3, C=C).fit(X_train, y_train)
#lin_svc = svm.LinearSVC(C=C).fit(X_train, y_train)


#print(y_pred)
print("Accuracy:",metrics.accuracy_score(y_test,y_test_pred))
#Accuracy: 0.9561643835616438

import matplotlib.pyplot as plt

#plt.scatter(X_train[:,0], X_train[:,1])
#plt.title('Linearly separable data')
#plt.xlabel('X1')
#plt.ylabel('X2')
#plt.show()

support_vectors = model_ozone.support_vectors_

# Visualize support vectors
plt.scatter(X_train[:,0], X_train[:,1])
plt.scatter(support_vectors[:,0], support_vectors[:,1], color='red')
plt.title('Ozone Day and Normal Day Prediction Software')
plt.xlabel('Data')
plt.ylabel('Class [Ozone Day = 1, Normal Day = 0]')
plt.show()

57 changes: 57 additions & 0 deletions svm-ozone-rbf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from sklearn.decomposition import PCA
from sklearn import svm
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn import metrics
import pandas as pd
#from sklearn.preprocessing import LabelEncoder

#read data
df = pd.read_csv('ozone-data.csv')
#print(df.head())

#data select
X = df.iloc[:,1:73]
print(X)
#target select [class]
y = df.iloc[:,73:74]
print(y)
#target type of Dataframe to type of Numpy Array
yyy = np.array(y).ravel()

#train,test of creating
X_train, X_test, y_train, y_test = train_test_split(X,yyy,test_size=0.2880820836621942,random_state=49) # 80% training and 20% test


#creationg pca model
model_ozone = PCA(n_components=72).fit(X_train)
model_ozone_2d = model_ozone.transform(X_train)

#print(model_ozone_2d)e


#creating of model the SVM
model = svm.SVC(kernel='rbf', gamma=0.05, C=3)

#The model is training in equation
model.fit(model_ozone_2d, y_train)

#prediction equation is the model.
y_test_pred = model.predict(X_test)

#accuracy is model
print("Accuracy:",metrics.accuracy_score(y_test,y_test_pred))
#Accuracy: 0.9602739726027397

#data visualition
import pylab as pl
for i in range(0, model_ozone_2d.shape[0]):
if y_train[i] == 0:
c1 = pl.scatter(model_ozone_2d[i,0],model_ozone_2d[i,1],color='r',edgecolors='y',marker='*',linewidths=1)

elif y_train[i] == 1:
c2 = pl.scatter(model_ozone_2d[i,0],model_ozone_2d[i,1],color='g',edgecolors='y',marker='o',linewidths=1)
import matplotlib.pyplot as plt
pl.legend([c1, c2], ['Ozone Day', 'Normal Day'])
plt.title('Ozone and Normal Day Classification')
pl.show()

0 comments on commit 16323ca

Please sign in to comment.