WITH filtered_goods AS ( SELECT model FROM base_goods AS bg WHERE bg.type_one = 1 ), aggregated_orders AS ( SELECT og.goods_model, m.merchant_id, SUM( og.buy_num ) AS amount FROM order_goods AS og JOIN orders AS m ON og.order_id = m.id WHERE m.`status` IN ( 0, 2, 3, 5, 6, 8, 9, 10, 11, 17 ) AND og.goods_model IN ( SELECT model FROM filtered_goods ) GROUP BY m.merchant_id, og.goods_model ) SELECT m.merchant_id, m.goods_model, m.amount, bg.market_date, bg.short_name, mr.shop_name FROM aggregated_orders AS m JOIN base_goods AS bg ON m.goods_model = bg.model JOIN merchant AS mr ON m.merchant_id = mr.id
时间: 2023-12-06 13:40:16 浏览: 198
这是一段SQL查询语句,大致意思是根据一些条件过滤出符合要求的商品,然后统计出每个商家销售的该商品的数量。最后再将这些信息与商家名称、商品名称等信息一起查询出来。
具体来说,这个查询语句先用一个子查询过滤出类型为1的商品,然后在orders表和order_goods表中根据一些状态条件和商品型号条件筛选订单,统计出每个商家销售的每个商品数量,最后通过JOIN操作连接base_goods表和merchant表,查询出商品名称、市场时间、商家名称等信息。
相关问题
import pandas as pd from sklearn.preprocessing import MinMaxScaler from sklearn.model_selection import train_test_split from keras.models import Sequential from keras.layers import Dense from keras.models import load_model model = load_model('model.h5') # 读取Excel文件 data = pd.read_excel('D://数据1.xlsx', sheet_name='4') # 把数据分成输入和输出 X = data.iloc[:, 0:5].values y = data.iloc[:, 0:5].values # 对输入和输出数据进行归一化 scaler_X = MinMaxScaler(feature_range=(0, 6)) X = scaler_X.fit_transform(X) scaler_y = MinMaxScaler(feature_range=(0, 6)) y = scaler_y.fit_transform(y) # 将数据集分成训练集和测试集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) # 创建神经网络模型 model = Sequential() model.add(Dense(units=4, input_dim=4, activation='relu')) model.add(Dense(units=36, activation='relu')) model.add(Dense(units=4, activation='relu')) model.add(Dense(units=4, activation='linear')) # 编译模型 model.compile(loss='mean_squared_error', optimizer='sgd') # 训练模型 model.fit(X_train, y_train, epochs=100, batch_size=1257) # 评估模型 score = model.evaluate(X_test, y_test, batch_size=30) print('Test loss:', score) # 使用训练好的模型进行预测 X_test_scaled = scaler_X.transform(X_test) y_pred = model.predict(X_test_scaled) # 对预测结果进行反归一化 y_pred_int = scaler_y.inverse_transform(y_pred).round().astype(int) # 构建带有概率的预测结果 y_pred_prob = pd.DataFrame(y_pred_int, columns=data.columns[:4]) mse = ((y_test - y_pred) ** 2).mean(axis=None) y_pred_prob['Probability'] = 1 / (1 + mse - ((y_pred_int - y_test) ** 2).mean(axis=None)) # 过滤掉和值超过6或小于6的预测值 y_pred_filtered = y_pred_prob[(y_pred_prob.iloc[:, :4].sum(axis=1) == 6)] # 去除重复的行 y_pred_filtered = y_pred_filtered.drop_duplicates() # 重新计算低于1.2的 Probability 值 low_prob_indices = y_pred_filtered[y_pred_filtered['Probability'] < 1.5].index for i in low_prob_indices: y_pred_int_i = y_pred_int[i] y_test_i = y_test[i] mse_i = ((y_test_i - y_pred_int_i) ** 2).mean(axis=None) new_prob_i = 1 / (1 + mse_i - ((y_pred_int_i - y_test_i) ** 2).mean(axis=None)) y_pred_filtered.at[i, 'Probability'] = new_prob_i # 打印带有概率的预测结果 print('Predicted values with probabilities:') print(y_pred_filtered)
根据你之前的说明,应该是将第5行的代码从:
```python
model = load_model('model.h5')
```
改为:
```python
model = None
```
这样就可以重新声明一个没有用的 `model` 变量了。
import pandas as pd import numpy as np from sklearn.preprocessing import MinMaxScaler from sklearn.model_selection import train_test_split from keras.models import Sequential from keras.layers import Dense # 读取Excel文件 data = pd.read_excel('D://数据1.xlsx', sheet_name='8') # 把数据分成输入和输出 X = data.iloc[:, 0:8].values y = data.iloc[:, 0:8].values # 对输入和输出数据进行归一化 scaler_X = MinMaxScaler(feature_range=(0, 4)) X = scaler_X.fit_transform(X) scaler_y = MinMaxScaler(feature_range=(0, 4)) y = scaler_y.fit_transform(y) # 将数据集分成训练集和测试集 X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=0) # 创建神经网络模型 model = Sequential() model.add(Dense(units=8, input_dim=8, activation='relu')) model.add(Dense(units=64, activation='relu')) model.add(Dense(units=8, activation='relu')) model.add(Dense(units=8, activation='linear')) # 编译模型 model.compile(loss='mean_squared_error', optimizer='sgd') # 训练模型 model.fit(X_train, y_train, epochs=230, batch_size=1000) # 评估模型 score = model.evaluate(X_test, y_test, batch_size=1258) print('Test loss:', score) # 使用训练好的模型进行预测 X_test_scaled = scaler_X.transform(X_test) y_pred = model.predict(X_test_scaled) # 对预测结果进行反归一化 y_pred_int = scaler_y.inverse_transform(y_pred).round().astype(int) # 计算预测的概率 mse = ((y_test - y_pred) ** 2).mean(axis=None) probabilities = 1 / (1 + mse - ((y_pred_int - y_test) ** 2).mean(axis=None)) # 构建带有概率的预测结果 y_pred_prob = pd.DataFrame(y_pred_int, columns=data.columns[:8]) y_pred_prob['Probability'] = probabilities # 过滤掉和小于6或大于24的行 row_sums = np.sum(y_pred, axis=1) y_pred_filtered = y_pred[(row_sums >= 6) & (row_sums <= 6), :] # 去除重复的行 y_pred_filtered = y_pred_filtered.drop_duplicates() # 打印带有概率的预测结果 print('Predicted values with probabilities:') print(y_pred_filtered)显示Traceback (most recent call last): File "D:\pycharm\PyCharm Community Edition 2023.1.1\双色球8分区预测模型.py", line 61, in <module> y_pred_filtered = y_pred_filtered.drop_duplicates() AttributeError: 'numpy.ndarray' object has no attribute 'drop_duplicates'怎么修改
你需要将 `y_pred_filtered` 数组转换为 pandas DataFrame,然后再使用 `drop_duplicates()` 方法进行去重。你可以使用 `pd.DataFrame()` 将 numpy 数组转换为 DataFrame,如下所示:
```
import pandas as pd
import numpy as np
# ... 其他代码 ...
# 对 y_pred 进行过滤和去重
row_sums = np.sum(y_pred, axis=1)
y_pred_filtered = y_pred[(row_sums >= 6) & (row_sums <= 24), :]
y_pred_filtered_df = pd.DataFrame(data=y_pred_filtered, columns=data.columns[:8])
y_pred_filtered_df.drop_duplicates(inplace=True)
# 打印预测结果
print('Predicted values with probabilities:')
print(y_pred_filtered_df)
```
这应该可以解决你遇到的问题。
阅读全文