sololearn学习笔记Machine Learning-17

Building a Logistic Regression model.

任务

Task
You are given a feature matrix and a single datapoint to predict. Your job will be to build a Logistic Regression model with the feature matrix and make a prediction (1 or 0) of the single datapoint.

输入格式

First line: Number of data points in the feature matrix (n)
Next n lines: Values of the row in the feature matrix, separated by spaces
Next line: Target values separated by spaces
Final line: Values (separated by spaces) of a single datapoint without a target value

输出格式

Output Format
Either 1 or 0

输入案例

Sample Input
6
1 3
3 5
5 7
3 1
5 3
7 5
1 1 1 0 0 0
2 4

输出案例

Sample Output
1

代码

from sklearn.linear_model import LogisticRegression
import numpy as np
n = int(input())
X = []
for i in range(n):
    a = [float(x) for x in input().split()]
    X.append(a)
label = [int(x) for x in input().split()]
model = LogisticRegression(C=50)
X1 = [float(x) for x in input().split()]
X1 = np.reshape(X1, [1, -1])
model.fit(X, label)
predict = model.predict(X1)
print(predict[0])
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值