99import urllib .request
1010import zipfile
1111import os .path
12+ import tempfile
1213
1314from sklearn .multioutput import MultiOutputRegressor
1415
@@ -76,6 +77,27 @@ def convert_multiregressor(multi, out_dir, format=None, prefix='regressor', **kw
7677 converted .save (file = p , ** kwargs )
7778
7879
80+ def predict (data , model_dir ):
81+ """
82+ Make predictions using MicroPython model
83+ """
84+
85+ with tempfile .TemporaryDirectory () as temp_dir :
86+ #temp_dir = d.name
87+ temp_dir = '' # XXX: temp
88+
89+ input_path = os .path .join (temp_dir , 'input.npy' )
90+ output_path = os .path .join (temp_dir , 'output.npy' )
91+
92+ arr = np .ascontiguousarray (data .values ).astype (np .int16 )
93+ assert len (arr .shape ) == 2
94+ np .save (input_path , arr , allow_pickle = False )
95+
96+ #subprocess.check_output()
97+
98+ out = np .load (output_path )
99+ return outs
100+
79101
80102def main ():
81103
@@ -102,12 +124,27 @@ def main():
102124
103125 print ("Performance Metrics:" )
104126 print ("-" * 60 )
105- y_pred = pd .DataFrame (pipeline .predict (X_test ), columns = y_train .columns )
127+
128+
129+ y_pred_orig = pd .DataFrame (pipeline .predict (X_test ), columns = y_train .columns )
130+
131+
132+ X_test_scaled = pipeline .named_steps ['scaler' ].transform (X_test )
133+
134+ print (X_test .head ())
135+
136+ print (y_pred_orig .head ())
137+
138+ y_pred_converted = pd .DataFrame (predict (X_test_scaled , model_dir ), columns = y_train .columns )
139+
140+ y_pred = y_pred_converted
141+
106142 for i , target in enumerate (y .columns ):
143+
107144 rmse = np .sqrt (mean_squared_error (y_test [target ], y_pred [target ]))
108145 r2 = r2_score (y_test [target ], y_pred [target ])
109146 mape = mean_absolute_percentage_error (y_test [target ], y_pred [target ]) * 100
110-
147+
111148 print (f"{ target :12} | RMSE: { rmse :8.3f} | MAPE: { mape :6.2f} % | R²: { r2 :6.3f} " )
112149
113150if __name__ == '__main__' :
0 commit comments