我正在尝试创建一个图形,以日期为x轴绘制我的y_train
和y_pred
。我以前从未创建过这样的游戏,所以我有点困惑。我如何像下面的图示例一样创建它?到目前为止,我只能创建相似的图形,但线没有连接,如何使其连接?
X = np.array(covid.drop(['acc_deceased'],1))
y = np.array(covid['acc_deceased'])
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,
shuffle = False)
lr = LinearRegression()
lr.fit(X_train,y_train)
y_pred = lr.predict(X_test)
pred = pd.DataFrame(y_pred, columns = ['y_pred'])
train = pd.DataFrame(y_train,columns = ['y_train'])
final = pd.concat([train,pred],ignore_index=True,sort=False)
final = final.set_index(covid.index)
plt.figure(figsize=(10,5))
sns.lineplot(x=final.index, y=final['y_train'])
sns.lineplot(x=final.index, y=final['y_pred'])
plt.legend(['y_train','y_pred','y_test'],
loc='upper left')
plt.ylabel('y')
这是我的身材
答案 0 :(得分:1)
做您想做的事的最简单方法是:
ask people in-cone 1 180 [set color red]
但是 ,您还应该采取一些措施来验证模型。
为此,您可以从测试数据中得出预测,并使用sklearn内置的metrics:
// All valid credit card numbers
const valid1 = [4, 5, 3, 9, 6, 7, 7, 9, 0, 8, 0, 1, 6, 8, 0, 8]
const valid2 = [5, 5, 3, 5, 7, 6, 6, 7, 6, 8, 7, 5, 1, 4, 3, 9]
const valid3 = [3, 7, 1, 6, 1, 2, 0, 1, 9, 9, 8, 5, 2, 3, 6]
const valid4 = [6, 0, 1, 1, 1, 4, 4, 3, 4, 0, 6, 8, 2, 9, 0, 5]
const valid5 = [4, 5, 3, 9, 4, 0, 4, 9, 6, 7, 8, 6, 9, 6, 6, 6]
// All invalid credit card numbers
const invalid1 = [4, 5, 3, 2, 7, 7, 8, 7, 7, 1, 0, 9, 1, 7, 9, 5]
const invalid2 = [5, 7, 9, 5, 5, 9, 3, 3, 9, 2, 1, 3, 4, 6, 4, 3]
const invalid3 = [3, 7, 5, 7, 9, 6, 0, 8, 4, 4, 5, 9, 9, 1, 4]
const invalid4 = [6, 0, 1, 1, 1, 2, 7, 9, 6, 1, 7, 7, 7, 9, 3, 5]
const invalid5 = [5, 3, 8, 2, 0, 1, 9, 7, 7, 2, 8, 8, 3, 8, 5, 4]
// Can be either valid or invalid
const mystery1 = [3, 4, 4, 8, 0, 1, 9, 6, 8, 3, 0, 5, 4, 1, 4]
const mystery2 = [5, 4, 6, 6, 1, 0, 0, 8, 6, 1, 6, 2, 0, 2, 3, 9]
const mystery3 = [6, 0, 1, 1, 3, 7, 7, 0, 2, 0, 9, 6, 2, 6, 5, 6, 2, 0, 3]
const mystery4 = [4, 9, 2, 9, 8, 7, 7, 1, 6, 9, 2, 1, 7, 0, 9, 3]
const mystery5 = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]
// An array of all the arrays above
const batch = [valid1, valid2, valid3, valid4, valid5, invalid1, invalid2, invalid3, invalid4, invalid5, mystery1, mystery2, mystery3, mystery4, mystery5];
isValidCard = (array) => {
let copy = [...array];
const last = copy.pop();
copy.reverse();
copy = copy.map((dig, i) => ((i % 2 === 0 ? dig * 2 : dig)));
copy = copy.map(dig => (dig > 9 ? dig - 9 : dig));
const sum = copy.reduce((acc, curr) => acc + curr);
return ((sum + last) % 10 === 0);
}
findInvalidCards = (array) => {
const validList = [];
const invalidList = [];
array.forEach(card => {
if (isValidCard(card)) {
validList.push(card);
} else {
invalidList.push(card);
}
});
console.log('valid cards', validList);
console.log('invalid cards', invalidList);
}
findInvalidCards(batch);
希望有帮助!