File size: 1,912 Bytes
69bc517
 
 
 
 
c1f976e
 
69bc517
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys
import pandas as pd
from projects.ML_StudentPerformance.src.exception import CustomException
from projects.ML_StudentPerformance.src.utils import load_object

model_path = 'projects/ML_StudentPerformance/artifacts/model.pkl'
preprocessor_path = 'projects/ML_StudentPerformance/artifacts/preprocessor.pkl'

class PredictPipeline():
    def __init__(self):
        pass
    def predict(self, features):
        try:
            model = load_object(file_path = model_path)
            preprocessor = load_object(file_path=preprocessor_path)
            data_scaled = preprocessor.transform(features)
            prediction = model.predict(data_scaled)

            return prediction
        except Exception as e:
            raise CustomException(e, sys)
    
class CustomData():
    def __init__(self, gender:str, race_ethnicity:str, parental_level_of_education, lunch:str, test_preparation_course:str, reading_score:int, writing_score:int):
        self.gender = gender
        self.race_ethnicity = race_ethnicity
        self.parental_level_of_education = parental_level_of_education
        self.lunch = lunch
        self.test_preparation_course = test_preparation_course
        self.reading_score = reading_score
        self.writing_score = writing_score

    def get_data_as_dataframe(self):
        try:
            custom_data_input_dict = {
                "gender" : [self.gender],
                "race_ethnicity" : [self.race_ethnicity],
                "parental_level_of_education": [self.parental_level_of_education],
                "lunch": [self.lunch],
                "test_preparation_course": [self.test_preparation_course],
                "reading_score": [self.reading_score],
                "writing_score": [self.writing_score],
            }

            return pd.DataFrame(custom_data_input_dict)
        except Exception as e:
            raise CustomException(e,sys)