コード例 #1
0
ファイル: test.py プロジェクト: Karocyt/PiscineML
def test3():
    # Example 3:
    print(cost_elem_(y2, y_hat2))
    print(np.array([[1.3203125], [0.7503125], [0.0153125], [2.1528125]]))
    assert (cost_elem_(y2, y_hat2) == np.array([[1.3203125], [0.7503125],
                                                [0.0153125],
                                                [2.1528125]])).all()
コード例 #2
0
ファイル: test.py プロジェクト: Karocyt/PiscineML
def test1():
    # Example 1:
    assert (cost_elem_(y1, y_hat1) == np.array([[0.], [0.1], [0.4], [0.9],
                                                [1.6]])).all()
コード例 #3
0
ファイル: test.py プロジェクト: gbiebuyc/Bootcamp-ML
#!/usr/bin/env python3
from cost import cost_, cost_elem_
from prediction import predict_
import numpy as np

x1 = np.array([[0.], [1.], [2.], [3.], [4.]])
theta1 = np.array([[2.], [4.]])
y_hat1 = predict_(x1, theta1)
y1 = np.array([[2.], [7.], [12.], [17.], [22.]])

output = cost_elem_(y1, y_hat1)
print('Example 1:', output.tolist())
#assert np.array_equal(output, [[0.], [0.1], [0.4], [0.9], [1.6]])

output = cost_(y1, y_hat1)
print('Example 2:', output)

x2 = np.array([[0.2, 2., 20.], [0.4, 4., 40.], [0.6, 6., 60.], [0.8, 8., 80.]])
theta2 = np.array([[0.05], [1.], [1.], [1.]])
y_hat2 = predict_(x2, theta2)
y2 = np.array([[19.], [42.], [67.], [93.]])

output = cost_elem_(y2, y_hat2)
print('Example 3:', output.tolist())

output = cost_(y2, y_hat2)
print('Example 4:', output)

x3 = np.array([0, 15, -9, 7, 12, 3, -21])
theta3 = np.array([[0.], [1.]])
y_hat3 = predict_(x3, theta3)
コード例 #4
0
import numpy as np
from cost import cost_, cost_elem_
from prediction import predict_

x1 = np.array([[0.], [1.], [2.], [3.], [4.]])
theta1 = np.array([[2.], [4.]])

y_hat1 = predict_(x1, theta1)
print(y_hat1)

y1 = np.array([[2.], [7.], [12.], [17.], [22.]])

# Example 1:
print(cost_elem_(y1, y_hat1))
# Output:
# array([[0.], [0.1], [0.4], [0.9], [1.6]])

# Example 2:
print(cost_(y1, y_hat1))
# Output:
# 3.0

x2 = np.array([[0.2, 2., 20.], [0.4, 4., 40.], [0.6, 6., 60.], [0.8, 8., 80.]])
theta2 = np.array([[0.05], [1.], [1.], [1.]])
y_hat2 = predict_(x2, theta2)
y2 = np.array([[19.], [42.], [67.], [93.]])

# Example 3:
print(cost_elem_(y2, y_hat2))
# Output:
# array([[1.3203125], [0.7503125], [0.0153125], [2.1528125]])
コード例 #5
0
from cost import cost_elem_, cost_
from prediction import predict_
import numpy as np

x1 = np.arange(0, 5)
theta1 = np.array([2, 4])
y_hat1 = predict_(x1, theta1)
y1 = np.array([2, 7, 12, 17, 22])
print(repr(cost_elem_(y1, y_hat1)))
print(repr(cost_(y1, y_hat1)))