Created
July 25, 2022 05:09
-
-
Save sasankaweera123/a536e9062b0b79830cfebcfa09bb975f to your computer and use it in GitHub Desktop.
Basic ML Understanding Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.linear_model import LinearRegression | |
import random | |
feature_set = [] | |
target_set = [] | |
nRows = 200 | |
randomNLimit = 2000 | |
for i in range(0, nRows): | |
x = random.randint(0, randomNLimit) | |
y = random.randint(0, randomNLimit) | |
z = random.randint(0, randomNLimit) | |
function = (10*x)+(2*y)+(3*z) | |
feature_set.append([x, y, z]) | |
target_set.append(function) | |
# Model | |
model = LinearRegression() | |
model.fit(feature_set, target_set) | |
# Testing Data set | |
test_set = [[8, 4, 7]] # Expected Output = function(8,4,7) = (10*8) + (2*4) + (3*7) = 109 | |
prediction = model.predict(test_set) | |
test_set_2 = [[9, 2, 2]] # Expected Output = function(9,2,2) = (10*9) + (2*2) + (3*2) = 100 | |
prediction2 = model.predict(test_set_2) | |
print('Prediction:' + str(prediction) + ' Co - Efficient: ' + str(model.coef_)) | |
print('Prediction:' + str(prediction2) + ' Co - Efficient: ' + str(model.coef_)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment