vavelychko
commited on
Commit
•
25d9ae3
1
Parent(s):
9cfbab9
fix CustomNextPlaceModel.py
Browse files- CustomNextPlaceModel.py +30 -16
CustomNextPlaceModel.py
CHANGED
@@ -126,36 +126,50 @@ class CustomNextPlaceModel:
|
|
126 |
combined_dataset, _ = dp.create_convolution_features(combined_dataset, combined_dataset.columns.to_list(), 3)
|
127 |
|
128 |
# Predict B scores for different categories
|
129 |
-
score_B_1 = self.score_b_1.predict_proba_dataset(combined_dataset[combined_dataset['A']==1])
|
130 |
-
score_B_2 = self.score_b_2.predict_proba_dataset(combined_dataset[combined_dataset['A']==2])
|
131 |
-
score_B_3 = self.score_b_3.predict_proba_dataset(combined_dataset[combined_dataset['A']==3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
# Concatenate B scores
|
134 |
-
df_B = pd.concat([
|
|
|
|
|
135 |
|
136 |
# Further combine and process dataset
|
137 |
-
combined_dataset = dp.combine_datasets(
|
138 |
combined_dataset = combined_dataset.drop(columns=['0'])
|
139 |
combined_dataset, _ = dp.create_convolution_features(combined_dataset, combined_dataset.columns.to_list(), 3)
|
140 |
|
141 |
# Predict C scores for different categories
|
142 |
c_scores = {
|
143 |
'1': self.score_c_models['1'].predict_dataset(combined_dataset[combined_dataset['B'].isin([1])])
|
144 |
-
|
145 |
'2': self.score_c_models['2'].predict_dataset(combined_dataset[combined_dataset['B'].isin([2])])
|
146 |
-
|
147 |
'3_4': self.score_c_models['3_4'].predict_dataset(combined_dataset[combined_dataset['B'].isin([3, 4])])
|
148 |
-
|
149 |
'5_6': self.score_c_models['5_6'].predict_dataset(combined_dataset[combined_dataset['B'].isin([5, 6])])
|
150 |
-
|
151 |
'7': self.score_c_models['7'].predict_dataset(combined_dataset[combined_dataset['B'].isin([7])])
|
152 |
-
|
153 |
'8_9': self.score_c_models['8_9'].predict_dataset(combined_dataset[combined_dataset['B'].isin([8, 9])])
|
154 |
-
|
155 |
}
|
156 |
df_C = pd.concat(
|
157 |
[c_scores[key][['price']] for key in c_scores
|
158 |
-
|
|
|
159 |
ignore_index=True
|
160 |
)
|
161 |
|
@@ -178,12 +192,12 @@ class CustomNextPlaceModel:
|
|
178 |
result = self.predict(input_data)
|
179 |
predicted_sale_price, predicted_days = result['price'].iloc[0], result['days'].iloc[0] # кол-во дней нужно преобразовать в дату в виде строки
|
180 |
|
181 |
-
current_days_on_market = input_data.
|
182 |
|
183 |
# Вычисление даты размещения на рынке
|
184 |
-
date_listed = datetime.now() - timedelta(days=current_days_on_market)
|
185 |
|
186 |
# Вычисление предсказанной даты продажи
|
187 |
-
predicted_sale_date = (date_listed + timedelta(days=predicted_days)).strftime('%Y-%m-%d')
|
188 |
|
189 |
-
return predicted_sale_price, predicted_sale_date
|
|
|
126 |
combined_dataset, _ = dp.create_convolution_features(combined_dataset, combined_dataset.columns.to_list(), 3)
|
127 |
|
128 |
# Predict B scores for different categories
|
129 |
+
# score_B_1 = self.score_b_1.predict_proba_dataset(combined_dataset[combined_dataset['A']==1])
|
130 |
+
# score_B_2 = self.score_b_2.predict_proba_dataset(combined_dataset[combined_dataset['A']==2])
|
131 |
+
# score_B_3 = self.score_b_3.predict_proba_dataset(combined_dataset[combined_dataset['A']==3])
|
132 |
+
b_scores = {
|
133 |
+
'1': self.score_b_1.predict_proba_dataset(combined_dataset[combined_dataset['A'] == 1])
|
134 |
+
if not combined_dataset[combined_dataset['A'] == 1].empty else pd.DataFrame(
|
135 |
+
{'B_Probability_Class_0': [0], 'B_Probability_Class_1': [0], 'B_Probability_Class_2': [0]}),
|
136 |
+
'2': self.score_b_2.predict_proba_dataset(combined_dataset[combined_dataset['A'] == 2])
|
137 |
+
if not combined_dataset[combined_dataset['A'] == 2].empty else pd.DataFrame(
|
138 |
+
{'B_Probability_Class_0': [0], 'B_Probability_Class_1': [0], 'B_Probability_Class_2': [0]}),
|
139 |
+
'3': self.score_b_3.predict_proba_dataset(combined_dataset[combined_dataset['A'] == 3])
|
140 |
+
if not combined_dataset[combined_dataset['A'] == 3].empty else pd.DataFrame(
|
141 |
+
{'B_Probability_Class_0': [0], 'B_Probability_Class_1': [0], 'B_Probability_Class_2': [0]}),
|
142 |
+
}
|
143 |
|
144 |
# Concatenate B scores
|
145 |
+
df_B = pd.concat([b_scores['1'], b_scores['2'], b_scores['3']], ignore_index=True)
|
146 |
+
|
147 |
+
df_B_ = df_B.dropna()
|
148 |
|
149 |
# Further combine and process dataset
|
150 |
+
combined_dataset = dp.combine_datasets(df_B_, dp.X)
|
151 |
combined_dataset = combined_dataset.drop(columns=['0'])
|
152 |
combined_dataset, _ = dp.create_convolution_features(combined_dataset, combined_dataset.columns.to_list(), 3)
|
153 |
|
154 |
# Predict C scores for different categories
|
155 |
c_scores = {
|
156 |
'1': self.score_c_models['1'].predict_dataset(combined_dataset[combined_dataset['B'].isin([1])])
|
157 |
+
if not combined_dataset[combined_dataset['B'].isin([1])].empty else pd.DataFrame({'price': [0]}),
|
158 |
'2': self.score_c_models['2'].predict_dataset(combined_dataset[combined_dataset['B'].isin([2])])
|
159 |
+
if not combined_dataset[combined_dataset['B'].isin([2])].empty else pd.DataFrame({'price': [0]}),
|
160 |
'3_4': self.score_c_models['3_4'].predict_dataset(combined_dataset[combined_dataset['B'].isin([3, 4])])
|
161 |
+
if not combined_dataset[combined_dataset['B'].isin([3, 4])].empty else pd.DataFrame({'price': [0]}),
|
162 |
'5_6': self.score_c_models['5_6'].predict_dataset(combined_dataset[combined_dataset['B'].isin([5, 6])])
|
163 |
+
if not combined_dataset[combined_dataset['B'].isin([5, 6])].empty else pd.DataFrame({'price': [0]}),
|
164 |
'7': self.score_c_models['7'].predict_dataset(combined_dataset[combined_dataset['B'].isin([7])])
|
165 |
+
if not combined_dataset[combined_dataset['B'].isin([7])].empty else pd.DataFrame({'price': [0]}),
|
166 |
'8_9': self.score_c_models['8_9'].predict_dataset(combined_dataset[combined_dataset['B'].isin([8, 9])])
|
167 |
+
if not combined_dataset[combined_dataset['B'].isin([8, 9])].empty else pd.DataFrame({'price': [0]})
|
168 |
}
|
169 |
df_C = pd.concat(
|
170 |
[c_scores[key][['price']] for key in c_scores
|
171 |
+
if
|
172 |
+
isinstance(c_scores[key], pd.DataFrame) and 'price' in c_scores[key].columns and not c_scores[key].empty],
|
173 |
ignore_index=True
|
174 |
)
|
175 |
|
|
|
192 |
result = self.predict(input_data)
|
193 |
predicted_sale_price, predicted_days = result['price'].iloc[0], result['days'].iloc[0] # кол-во дней нужно преобразовать в дату в виде строки
|
194 |
|
195 |
+
current_days_on_market = input_data['days_on_market'].iloc[0] if 'days_on_market' in input_data else 0
|
196 |
|
197 |
# Вычисление даты размещения на рынке
|
198 |
+
date_listed = datetime.now() - timedelta(days=int(current_days_on_market))
|
199 |
|
200 |
# Вычисление предсказанной даты продажи
|
201 |
+
predicted_sale_date = (date_listed + timedelta(days=int(predicted_days))).strftime('%Y-%m-%d')
|
202 |
|
203 |
+
return float(predicted_sale_price), predicted_sale_date
|