helloworld.md 1.2 KB
Newer Older
F
feilong 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
# Hello World

HelloWorld, 请阅读如下代码:

```python
import numpy as np

def test():
    X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
    y = np.dot(X, np.array([1, 2])) + 3

    // TODO(选择选项中的代码填充此处)

    y_predict = reg.predict(np.array([[3, 5]]))
    print(y_predict)

if __name__ == '__main__':
    test()
```

若将以下选项中的代码分别填充到上述代码中**TODO**处,哪个选项不是线性模型?

## template

```java
import numpy as np

def test():
    X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])
    y = np.dot(X, np.array([1, 2])) + 3

    // 下面的 code 占位符会被替换成答案和选项代码
    $code

    y_predict = reg.predict(np.array([[3, 5]]))
    print(y_predict)

if __name__ == '__main__':
    test()
```


## 答案

```python
from sklearn import svm
reg = svm.SVC(kernel='rbf').fit(X, y)
```

## 选项

### 使用 LinearRegression

```python
from sklearn.linear_model import LinearRegression
reg = LinearRegression().fit(X, y)
```

### 使用岭回归

```python
from sklearn.linear_model import Ridge
reg = Ridge(alpha=0.1)
```

### 使用拉索算法

```python
from sklearn.linear_model import Lasso
reg = Lasso(alpha=0.1).fit(X, y)
```