0% found this document useful (0 votes)
17 views3 pages

Test 2

The document outlines a process for analyzing a dataset containing input frequency, input voltage, output current, and output voltage. It includes steps for data preparation, model training using linear regression, and evaluation of the model's performance, achieving a high R-squared score. Finally, it demonstrates saving and loading the trained model for future predictions.

Uploaded by

K R I S T
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)
17 views3 pages

Test 2

The document outlines a process for analyzing a dataset containing input frequency, input voltage, output current, and output voltage. It includes steps for data preparation, model training using linear regression, and evaluation of the model's performance, achieving a high R-squared score. Finally, it demonstrates saving and loading the trained model for future predictions.

Uploaded by

K R I S T
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/ 3

test_2

February 8, 2025

[1]: import pandas as pd

[2]: dataset=pd.read_csv("bulk.csv")

[3]: dataset

[3]: Input frequency (mhz) Input Voltage (V) Output Current (A) \
0 27 5.00 0.3560
1 27 5.45 0.3960
2 27 5.90 0.4368
3 27 6.35 0.4770
4 27 6.80 0.5171
.. … … …
95 27 47.75 4.1700
96 27 48.20 4.2100
97 27 48.65 4.2500
98 27 49.10 4.2900
99 27 49.55 4.3300

Output Voltage (V)


0 1.783
1 1.985
2 2.184
3 2.385
4 2.586
.. …
95 20.840
96 21.040
97 21.240
98 21.440
99 21.640

[100 rows x 4 columns]

[4]: independent=dataset[['Input frequency (mhz)','Output Current (A)']]

[5]: independent

1
[5]: Input frequency (mhz) Output Current (A)
0 27 0.3560
1 27 0.3960
2 27 0.4368
3 27 0.4770
4 27 0.5171
.. … …
95 27 4.1700
96 27 4.2100
97 27 4.2500
98 27 4.2900
99 27 4.3300

[100 rows x 2 columns]

[12]: dependent=dataset[["Output Voltage (V)"]]

[7]: dependent

[7]: Output Voltage (V)


0 1.783
1 1.985
2 2.184
3 2.385
4 2.586
.. …
95 20.840
96 21.040
97 21.240
98 21.440
99 21.640

[100 rows x 1 columns]

[15]: from sklearn.model_selection import train_test_split


X_train,X_test,y_train,y_test=train_test_split(independent, dependent,␣
↪test_size=0.30,random_state=0)

[16]: from sklearn.linear_model import LinearRegression


regressor=LinearRegression()
regressor.fit(X_train,y_train)

[16]: LinearRegression()

[17]: weight=regressor.coef_
weight

[17]: array([[0. , 4.99607798]])

2
[18]: bais=regressor.intercept_
bais

[18]: array([0.00880743])

[19]: y_pred=regressor.predict(X_test)

[20]: from sklearn.metrics import r2_score


r_score=r2_score(y_test,y_pred)

[21]: r_score

[21]: 0.9999966190491044

[22]: import pickle


filename="finalized_model_Mul_linear_bulk.sav"
pickle.dump(regressor,open(filename,'wb'))

[25]: loaded_model=pickle.load(open("finalized_model_Mul_linear_bulk.sav",'rb'))
result=loaded_model.predict([[27,4.25]])

C:\ProgramData\anaconda3\Lib\site-packages\sklearn\base.py:493: UserWarning: X
does not have valid feature names, but LinearRegression was fitted with feature
names
warnings.warn(

[26]: result

[26]: array([[21.24213884]])

[ ]:

You might also like