0% found this document useful (0 votes)
12 views2 pages

Multi - Class - Scaled - Down - Data - Colaboratory

This document discusses using a logistic regression model to classify multi-class spectroscopic data. The model is trained on preprocessed data and achieves 98% accuracy on test data. Cross validation is also performed and obtains 97% accuracy.

Uploaded by

Tahseen Jwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Multi - Class - Scaled - Down - Data - Colaboratory

This document discusses using a logistic regression model to classify multi-class spectroscopic data. The model is trained on preprocessed data and achieves 98% accuracy on test data. Cross validation is also performed and obtains 97% accuracy.

Uploaded by

Tahseen Jwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

10/23/23, 8:50 PM multi_class_scaled_down_data - Colaboratory

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import savgol_filter
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.dummy import DummyClassifier
from sklearn.pipeline import Pipeline
from sklearn.model_selection import GridSearchCV, cross_val_predict

from sklearn.metrics import classification_report, confusion_matrix, roc_curve


from sklearn.metrics import RocCurveDisplay, roc_auc_score

import sklearn.metrics as metrics

data = pd.read_csv('reflection spectrum-1000-LIPSS- 50 is the second training1000point.csv')

lab = data.values[:,1].astype('uint8') #labels


spectra = data.values[:,2:]
X = savgol_filter(spectra, 9, polyorder = 3, deriv=0)
X1 = savgol_filter(spectra, 11, polyorder = 3, deriv=1)

y=lab

lam=data.values[2,:]

pca = PCA(n_components=3)
Xpca = pca.fit_transform(StandardScaler().fit_transform(X1[:,:]))

X_train=X
y_train=y

data2 = pd.read_csv('reflection spectrum-1000-LIPSS- 50 is the second test1000 point.csv')

y_test = data2.values[:,1].astype('uint8') #labels


spectra2 = data2.values[:,2:]
X_test = savgol_filter(spectra2, 9, polyorder = 3, deriv=0)
#X1 = savgol_filter(spectra, 11, polyorder = 3, deriv=1)

#pca = PCA(n_components=3)
#Xpca = pca.fit_transform(StandardScaler().fit_transform(X1[:,:]))

model=LogisticRegression(max_iter=10000000)

model.fit(X_train,y_train)

/usr/local/lib/python3.10/dist-packages/sklearn/linear_model/_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=


STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT.

Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
n_iter_i = _check_optimize_result(
▾ LogisticRegression
LogisticRegression(max_iter=10000000)

model.score(X_test,y_test)

0.98

y_predict = model.predict(X_test)
print(classification_report(y_test, y_predict))
print(confusion_matrix(y_test, y_predict))

precision recall f1-score support

1 0.95 1.00 0.98 200


2 0.95 0.91 0.93 200
3 0.95 0.95 0.95 200
4 1.00 0.98 0.99 200
5 1.00 1.00 1.00 200

https://colab.research.google.com/drive/1isgyoxah8Nbaux_2S1vzA2kcx7r0P_MX#scrollTo=VRLRBWpi2X0b&printMode=true 1/2
10/23/23, 8:50 PM multi_class_scaled_down_data - Colaboratory
6 1.00 1.00 1.00 200
7 1.00 1.00 1.00 200
8 1.00 0.99 1.00 200

accuracy 0.98 1600


macro avg 0.98 0.98 0.98 1600
weighted avg 0.98 0.98 0.98 1600

[[200 0 0 0 0 0 0 0]
[ 10 181 9 0 0 0 0 0]
[ 0 9 191 0 0 0 0 0]
[ 0 0 2 197 1 0 0 0]
[ 0 0 0 0 200 0 0 0]
[ 0 0 0 0 0 200 0 0]
[ 0 0 0 0 0 0 200 0]
[ 0 0 0 0 0 1 0 199]]

y_cv = cross_val_predict(LogisticRegression(max_iter=3000), X_train, y_train, cv=5, n_jobs=8 )


print(classification_report(y_train, y_cv))
print(confusion_matrix(y_train, y_cv))

precision recall f1-score support

1 0.94 0.92 0.93 800


2 0.89 0.91 0.90 800
3 0.95 0.96 0.95 800
4 0.98 0.98 0.98 800
5 0.98 0.98 0.98 800
6 0.99 0.99 0.99 800
7 0.99 1.00 0.99 800
8 0.99 0.99 0.99 800

accuracy 0.97 6400


macro avg 0.97 0.97 0.97 6400
weighted avg 0.97 0.97 0.97 6400

[[736 64 0 0 0 0 0 0]
[ 43 725 32 0 0 0 0 0]
[ 0 24 766 8 0 0 2 0]
[ 0 0 8 783 9 0 0 0]
[ 0 0 0 9 787 4 0 0]
[ 0 0 0 3 3 791 1 2]
[ 0 0 0 0 0 0 797 3]
[ 0 0 0 0 0 1 3 796]]

https://colab.research.google.com/drive/1isgyoxah8Nbaux_2S1vzA2kcx7r0P_MX#scrollTo=VRLRBWpi2X0b&printMode=true 2/2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy