Skip to content
Snippets Groups Projects
Commit bb57a854 authored by Steinmann's avatar Steinmann
Browse files

alle .csv hinzugefügt und Regression implementiert

parent 2e3329f4
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
Pumpenkennlinien importieren und auf Pumpengleichung Fitten
aus Webplotdigitizer .csv datei eines Plots extrahieren
mit pandas read_csv importieren
-> rechenspaß
->Profit!!!
Q^2 -> Q_sq quit
Multiple Linear Regression with Intercept
Q^3, Q^2
pandas -> read_csv
%% Cell type:code id: tags:
``` python
!pip install pandas
!pip install numpy
!pip install matplotlib
!pip install scikit-learn
```
%% Cell type:markdown id: tags:
Zusammenhänge der Pumpe:
$\Delta p=\alpha_1\cdot Q^2+\alpha_2\cdot Q\cdot n_{est}+\alpha_3\cdot n_{est}^2$
$l_{est}=\frac{\Delta p}{Q^2}$
Leistungsgleichung:
$P_{est}=\beta_1\cdot Q^3+\beta_2 Q^2\cdot n_{est}+\beta_3\cdot Qn_{est}^2+\beta_4n^3+\beta_5$
%% Cell type:code id: tags:
``` python
#implementierung einer linearen Regression
#Implementierung des .csv zu DataFrame converters
import pandas as pd
def csv_einlesen(y_Achse,drehzahl):
with open('{0}-Q_kennlinie_n_{1}.csv'.format(y_Achse,drehzahl)) as kennlinie:
dataframe = pd.read_csv(kennlinie, delimiter=';')
sorted_set = dataframe.set_axis(['Q','h'],axis='columns')
sorted_set.sort_values(by='Q',inplace=True)
#im Datensatz alle ',' durch '.' ersetzen und die String werte als Float Werte casten
for x in sorted_set.index:
for y in sorted_set.columns:
sorted_set.loc[x,[y]] = sorted_set.loc[x,[y]].str.replace(',','.')
sorted_set.loc[x,[y]] = sorted_set.loc[x,[y]].astype(float)
#berechnen der Spalte Q^2, Q^3 n_relativ, n^2, n^3, Q*n, Q^2*n,Q*n^2
sorted_set['Q^2'] = sorted_set['Q'] **2
sorted_set['Q^3'] = sorted_set['Q'] **3
sorted_set['n_rel'] = drehzahl/3600
sorted_set['n^2'] = (sorted_set['n_rel']*3600)**2
sorted_set['n^3'] = (sorted_set['n_rel']*3600)**3
sorted_set['Qn'] = (sorted_set['n_rel']*3600)*sorted_set['Q']
sorted_set['Q^2n'] = sorted_set['Q^2']*3600*sorted_set['n_rel']
sorted_set['Qn^2'] = sorted_set['Q']*sorted_set['n^2']
sorted_set.set_index('Q',inplace=True)
return sorted_set
```
%% Cell type:code id: tags:
``` python
print(csv_einlesen('h',3600).loc[:,['Q^2','Qn','n^2']])
import numpy as np
print(csv_einlesen('h',2900).loc[:,['Q^2','Qn','n^2']].to_numpy(float))
```
%% Output
Q^2 Qn n^2
Q
0.011261 0.000127 40.540541 12960000.0
1.0 1.0 3600.0 12960000.0
1.5 2.25 5400.0 12960000.0
2.0 4.0 7200.0 12960000.0
2.5 6.25 9000.0 12960000.0
3.0 9.0 10800.0 12960000.0
3.5 12.25 12600.0 12960000.0
4.0 16.0 14400.0 12960000.0
4.5 20.25 16200.0 12960000.0
5.0 25.0 18000.0 12960000.0
5.5 30.25 19800.0 12960000.0
6.0 36.0 21600.0 12960000.0
6.5 42.25 23400.0 12960000.0
7.0 49.0 25200.0 12960000.0
7.5 56.25 27000.0 12960000.0
8.0 64.0 28800.0 12960000.0
8.5 72.25 30600.0 12960000.0
9.0 81.0 32400.0 12960000.0
9.5 90.25 34200.0 12960000.0
%% Cell type:markdown id: tags:
Fitting aus den Kurven mit sklearn
%% Cell type:code id: tags:
``` python
import numpy as np
from matplotlib import pyplot as plt
from sklearn.linear_model import LinearRegression
df = csv_einlesen('h',3600)
X= df.loc[:,['Q^2','Qn','n^2']].to_numpy(float)
y = df.index
results = LinearRegression(fit_intercept=False).fit(X,y)
print(results.score(X,y))
results = pd.DataFrame()
drehz = [750,1150,1500,1850,2200,2550,2900,3600]
results['n'] = drehz#get methode richtig verwenden spart die zeile
fig, (ax1,ax2) = plt.subplots(2,1,sharex=True)
ax1.set_title('Förderhöhe Kennlinie',loc='center')
ax2.set_title('Leistungskennlinien',loc='center')
for n in results.index:
df = csv_einlesen('h',drehz[n])
X = df.loc[:,['Q^2','Qn','n^2']].to_numpy(float)
y = df['h'].to_numpy(float)
results['Q-h_fit'] = LinearRegression(fit_intercept=False).fit(X,y)
#results['h_ber']
#for i in df.index:
# np.dot(df.loc[i,['Q^2','Qn','n^2']], results['Q-h_fit'].get(n).coef_)
X2 =df.loc[:,['Q^3','Q^2n','Qn^2','n^3']].to_numpy(float)
results['Q-P_fit'] = LinearRegression().fit(X2,y)
ax1.plot(df.index.to_numpy(),results['Q-h_fit'].get(n).predict(X))
ax2.plot(df.index.to_numpy(),results['Q-P_fit'].get(n).predict(X2))
print(results)
```
%% Output
1.0
n Q-h_fit Q-P_fit
0 750 LinearRegression(fit_intercept=False) LinearRegression()
1 1150 LinearRegression(fit_intercept=False) LinearRegression()
2 1500 LinearRegression(fit_intercept=False) LinearRegression()
3 1850 LinearRegression(fit_intercept=False) LinearRegression()
4 2200 LinearRegression(fit_intercept=False) LinearRegression()
5 2550 LinearRegression(fit_intercept=False) LinearRegression()
6 2900 LinearRegression(fit_intercept=False) LinearRegression()
7 3600 LinearRegression(fit_intercept=False) LinearRegression()
......
0,4997431821275309; 0,013781039147448826
0,9999999999999987; 0,015480575653592676
1,4999999999999987; 0,01781397928321593
1,9999999999999996; 0,020290346654134817
2,4999999999999987; 0,021623336515153524
2,9999999999999996; 0,024132902337116124
3,4999999999999987; 0,02611156561969863
3,9999999999999996; 0,027090727200172082
4,486197323444136; 0,02832927133065044
5,02605417316202; 0,029405440943446215
5,520916531623271; 0,03048325419062564
-0,0008218171919018857; 0,011689527737614336
0,000333863234209808; 0,01607863509053964
0,49999999999999956; 0,019080344044859254
0,9999999999999996; 0,022780026877651738
1,4999999999999987; 0,02596131415691627
1,9996404549785418; 0,029488546671543936
2,4999999999999996; 0,032618019645384355
2,9999999999999996; 0,035874813717092446
3,499999999999998; 0,03837178864917423
3,9999999999999996; 0,04162154482794128
4,5; 0,04422720135234187
5; 0,0470186217898419
5,500000000000002; 0,0482144930065716
5,999999999999998; 0,050050244581489045
6,486808549980614; 0,05163518507579984
0; 0,023895122857550077
0,5; 0,027560630545292175
0,9999999999999987; 0,032314110288882925
1,4999999999999996; 0,0364419748965234
1,9999999999999987; 0,04126933621491158
2,4999999999999987; 0,04625409585604867
2,9999999999999996; 0,05100877723779129
3,4999999999999987; 0,055755900458728413
4,00007704536174; 0,060465042507183986
4,5; 0,06441656381192484
5,000000000000002; 0,06841035973942883
5,5; 0,07240224901945586
6; 0,07546347767443484
6,499999999999998; 0,07808856313897244
7; 0,08121262219342845
7,499999999999998; 0,08259153092873284
7,991838328012923; 0,08409162234418216
0,0003338632342106962; 0,032385441905489365
0,5; 0,03824274909839187
0,9999999999999996; 0,04435089827332511
1,4999999999999987; 0,05047607879105359
1,9999999999999987; 0,05734949736906603
2,4999999999999987; 0,06390013415847867
2,9999999999999996; 0,07091538059959573
3,499999999999998; 0,07734570525641055
3,9999999999999996; 0,0837072666442284
4,499999999999998; 0,09003781433209862
5; 0,09653695730442424
5,5; 0,10216054010581205
6; 0,1074816790617199
6,5; 0,11233372728564911
6,999999999999998; 0,11742328986864597
7,4999999999999964; 0,12075380841393707
8; 0,12498588060847077
8,5; 0,1270224560577347
8,978609639402027; 0,12825648914559257
-0,0000513635744940899; 0,04491015310106161
0,49999999999999956; 0,05202994294426022
0,9999999999999996; 0,059839225225622406
1,4999999999999987; 0,06790830644079776
1,9999999999999987; 0,07698295989091225
2,4999999999999996; 0,08539767156037775
2,9999999999999987; 0,09455322551269757
3,4999999999999996; 0,10381211664810436
3,9999999999999996; 0,11249978961244905
4,5; 0,12143764607733043
5; 0,13018934666509535
5,5; 0,1376533543323592
5,989470467228758; 0,1446960336681169
6,489187967569039; 0,15014404397067366
7,000128408936234; 0,15478696393213992
0,000385226808704342; 0,06007066819843471
0,49997431821275296; 0,06844683935744794
0,9999999999999996; 0,07861210411464203
1,4999999999999987; 0,08979382501942479
1,9999999999999996; 0,1013495891389325
2,4999999999999996; 0,11243520474522684
3,000308181446963; 0,12282099578786526
3,4776054815206687; 0,13114615392950218
3,9999999999999996; 0,1389853050746946
0,0001027271489881798; 0,0781354007136918
0,5; 0,08808223876268223
0,9999999999999987; 0,09724833024816187
1,4999999999999987; 0,10610436664260076
1,9999999999999987; 0,11433247142325448
2,4999999999999987; 0,12056830299293331
2,9999999999999987; 0,12720949027291717
3,4999999999999987; 0,1326065230712658
3,9999999999999996; 0,1389853050746946
4,5; 0,14330518803064624
5; 0,14771394826441298
5,5; 0,15186252703941644
6; 0,15493921273521566
6,5; 0,15644847330293243
7; 0,15661345264114207
7,499999999999998; 0,15725574096796496
8; 0,15725574096793088
8,500000000000002; 0,1570221790451155
9; 0,15531746520244405
9,5; 0,15467248444057063
10,011710894984606; 0,153424229738996
0,4886486500368532; 0,004870476593899609
0,9999999999999996; 0,004970368805329972
1,4999999999999987; 0,005489739175194852
1,9999999999999996; 0,006135234247208798
2,4999999999999996; 0,006135642605529401
-0,0002824996597166063; 0,004018275159805018
-4,440892098500626e-16; 0,8324179260031315
0,5; 0,872347328408626
1,0000000000000004; 0,8450333700033621
1,5000000000000004; 0,8374361646690982
2,0000000000000004; 0,8073567764182545
2,5000000000000004; 0,7196349001342401
3,0000000000000004; 0,6585042445978324
3,4999999999999996; 0,5213633403081896
4,009009009009009; 0,3947368421052637
-4,440892098500626e-16; 1,4214590932777504
0,5; 1,4588762159444126
1,0000000000000004; 1,4821784492255698
1,5000000000000004; 1,4655132881707313
2,0000000000000004; 1,4385260414966545
2,5000000000000004; 1,3755193415184372
3,0000000000000004; 1,3349675767207163
3,4999999999999996; 1,2065035491706944
3,9999999999999996; 1,1095808874965396
4,5; 0,9791118027736374
5; 0,8224546328922138
-4,440892098500626e-16; 2,1918368942157365
0,5; 2,2532046539914443
1,0000000000000004; 2,2858493461828964
1,5000000000000004; 2,2855028647754168
2,0000000000000004; 2,2506096925482506
2,5000000000000004; 2,21297965435401
3,0000000000000004; 2,134247310500589
3,4999999999999996; 2,088879671847913
3,9999999999999996; 1,9487400195095699
4,5; 1,8398350017490355
5; 1,6892366642931194
5,499999999999998; 1,5146854115947086
6; 1,3283623645101859
6,5; 1,1170297011874943
0,39999999999999947; 3,1929717878037955
0,6000000000000001; 3,192726374350473
0,7999999999999994; 3,227609113998083
1,0000000000000004; 3,2280257726231643
1,1999999999999988; 3,2276181873772227
1,4; 3,2276185513288276
1,6; 3,2276185513288276
1,7999999999999994; 3,2276185513288276
1,9999999999999987; 3,2276185247292286
2,199999999999999; 3,192725334193545
2,4; 3,1927253778009472
2,6; 3,192725468875448
2,8000000000000003; 3,172201212108755
3,0000000000000004; 3,1245879982583435
3,1999999999999997; 3,1054925087317535
3,4; 3,1054873601235773
3,6; 3,0705943576560895
3,8000000000000003; 3,0355394677905316
3,9999999999999996; 2,968977675571594
4,200000000000001; 2,9484434735780987
4,4; 2,9135787412991068
4,600000000000001; 2,8657924094465077
4,799999999999999; 2,7914239297767907
5,000000000000002; 2,740887534848481
5,200000000000001; 2,691857025461701
5,400000000000002; 2,599612325831064
5,600000000000001; 2,573879851181795
5,8000000000000025; 2,4776931153807205
6,000000000000002; 2,3992310266958743
6,200000000000001; 2,2983952347537553
6,4; 2,246752045742573
6,600000000000003; 2,128808780486329
6,8000000000000025; 2,0492925389296115
7,0000000000000036; 1,9410278530712048
7,200000000000003; 1,8499198549140576
7,400000000000004; 1,7671549591940021
7,600000000000003; 1,6564631012492335
8,000000000000004; 1,4020451875394127
7,7477477477477485; 1,578947368421053
0,22522522522522515; 3,1578947368421044
0; 3,078947368421053
0,5; 4,291860429116973
1,0000000000000004; 4,326955331949941
1,5000000000000004; 4,3616466909849
2,0000000000000004; 4,340796872874408
2,5000000000000004; 4,326753517457021
3,0000000000000004; 4,291842205604224
3,4999999999999996; 4,239149445560999
3,9999999999999996; 4,167048221276245
4,5; 4,0755034088799516
5; 3,984406827349039
5,499999999999998; 3,853047932821921
6; 3,687401555191453
6,5; 3,4719609924602004
6,999999999999998; 3,255362644235854
7,499999999999998; 2,9980586054421483
7,999999999999998; 2,7250400431129282
8,5; 2,437538409349431
9,00900900900901; 2,1315789473684195
0; 4,184210526315789
0,5; 8,477893910103
1,0000000000000004; 8,303953173252335
1,5000000000000004; 8,105201419575549
2,0000000000000004; 7,88174717906121
2,5000000000000004; 7,626840697332545
3,0000000000000004; 7,354029690343628
3,4999999999999996; 7,0570045428317005
3,9999999999999996; 6,732054821804168
4,5; 6,406415316112362
5; 6,063974237815968
5,499999999999998; 5,719840446210469
6; 5,343856753528749
6,5; 4,963474474341147
6,999999999999998; 4,573962765439893
7,499999999999998; 4,159159502939376
7,999999999999998; 3,757221910839121
8,5; 3,3249634825980987
9; 2,889809771547011
9,5; 2,4469590692331202
0,011261261261260813; 8,427631578947366
0; 8,450886912869716
0,5000000000000004; 8,48516771427629
-4,440892098500626e-16; 0,33946400329310933
0,5; 0,36557661893103877
1; 0,35812183010060394
1,4999999999999991; 0,29664919955389735
1,9999999999999991; 0,24371837171201882
2,5084364454443193; 0,17724288840262226
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment