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

added return for Liner Regression in .py

parent 9dab6caa
Branches
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
Graphen und Matrizen
%% Cell type:code id: tags:
``` python
!pip install networkx
!pip install matplotlib
```
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
import networkx as nx
def constuct_graph(*nodes):
#erstelle einen leeren Graphen
graph = nx.MultiDiGraph()
sizeA = 1
for arg in nodes:
if sizeA < len(arg):
sizeA=len(arg)
else:
continue
#erstelle einen Knoten für alle Übergebenen Knoten
for node in nodes:
#für jeden String in den übergebenen Daten wird ein Knoten erstellt
if isinstance(node, str):
graph.add_node(node)
#für jeden übergebenen touple der 2 knoten enthält wird eine Kante erstellt
elif isinstance(node , tuple) and len(node)==2 :
if isinstance(node.__getitem__(0),str) and isinstance(node.__getitem__(1),str):
graph.add_edge(node.__getitem__(0), node.__getitem__(1))
else:
print('Kante enthält unbekannten Knoten')
else:
print('Argument ist weder knoten noch Kante')
continue
pos = nx.spring_layout(graph)
pos = nx.planar_layout(graph)
#berechnung der Knotengröße entsprechend der Beschriftungs argumente
nx.draw_networkx_nodes(graph, pos, node_size = sizeA*325, node_color='white', edgecolors='black',linewidths=1)
nx.draw_networkx_edges(graph, pos, edge_color='black',node_size=sizeA*275, arrowsize=20)
nx.draw_networkx_labels(graph, pos)
return graph
```
%% Cell type:code id: tags:
``` python
a=constuct_graph('pumpA','valve1','valve2', ('pumpA', 'valve1') , ('valve1','valve2') , (5,6,7))
```
%% Output
Argument ist weder knoten noch Kante
%% Cell type:markdown id: tags:
Inzidenzmatrix aus Graphen
%% Cell type:code id: tags:
``` python
matrix = nx.incidence_matrix(a, oriented=True)
print(matrix)
```
%% Output
<Compressed Sparse Column sparse array of dtype 'float64'
with 4 stored elements and shape (3, 2)>
Coords Values
(0, 0) -1.0
(1, 0) 1.0
(1, 1) -1.0
(2, 1) 1.0
......
......@@ -49,3 +49,4 @@ def regress_pump():
plt.tight_layout()
print(f'R^2{LR_H.score(X,df['H'])}')
print(f'R^2{LR_P.score(X2,df['P'])}')
return LR_H,LR_P
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment