Team Ai
Apppublic

AlainDeLong/End-To-End-Machine-Learning-Project

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
data_transformation.cpython-38.pyc31 linesDownload Raw Back to __pycache__
1U

2���f��@s�ddlZddlZddlmZddlZddlZddlm	Z	ddl3mZddlm
Z
ddlmZmZddlmZddlmZdd	lmZeGd4d�d��ZGdd
�d
�ZdS)�N)�	dataclass)�Pipeline)�ColumnTransformer)�
SimpleImputer)�
OneHotEncoder�StandardScaler)�logging)�CustomException)�save_objectc@seZdZej�dd�ZdS)�DataTransformationConfig�	artifactszpreprocessor.pklN)�__name__�5__module__�__qualname__�os�path�join�preprocessor_obj_file_path�rr�R/home/long/Projects/machine-learning-project/src/components/data_transformation.pyrsrc@s*eZdZdd�dd�Zdd�Zdd�ZdS)	�DataTransformationN)�returncCst�|_dS)N)r�data_transformation_config)�selfrrr�__init__szDataTransformation.__init__c6Cs�z�ddg}dddddg}tdtd	d7�fdt�fgd�}t�d
�tdtdd8�fdt�fgd�}t�d�t�d|���t�d|���td||fd||fgd�}|WStk9r�}zt|t	��W5d}~XYnXdS)zF10        This function is responsible for data transformation11        Z
reading_scoreZ
writing_scoreZgenderZrace_ethnicityZparental_level_of_educationZlunchZtest_preparation_courseZimputer�median)�strategyZscaler)�stepsz,Numerical columns standard scaling completedZ
most_frequentZone_hot_encoderz&Categorical columns encoding completedzNumerical columns: zCategorical columns: �num_pipeline�cat_pipeline)ZtransformersN)12rrrr�inforr�	Exceptionr	�sys)rZnumerical_columnsZcatogrical_columnsrrZpreprocessor�errr�get_data_transformer_objects<���13��14��z.DataTransformation.get_data_transformer_objectc15Csz�t�|�}t�|�}t�d�t�d�|��}d}|j|gdd�}||}|j|gdd�}	||}16t�d�|�|�}|�|	�}tj	|t�17|�f}
tj	|t�18|19�f}t|jj
|d�t�d�|
||jj
fWStk20�r}zt|t��W5d}~XYnXdS)	Nz"Read train and test data completedzObtaining preprocessing objectZ21math_score�)�columns�axisz?Applying preprocessing object on training and testing dataframe)�	file_path�objzSaved preprocessing object)�pd�read_csvrr r$�drop�
fit_transform�	transform�np�c_�arrayr22rrr!r	r")rZ23train_pathZ	test_pathZtrain_dfZtest_dfZpreprocessing_objZtarget_column_nameZinput_feature_train_dfZtarget_feature_train_dfZinput_feature_test_dfZtarget_feature_test_dfZinput_feature_train_arrZinput_feature_test_arr�	train_arr�test_arrr#rrr�initiate_data_transformationHsB24252627��28��29�z/DataTransformation.initiate_data_transformation)r
rrrr$r4rrrrrs.r)rr"�dataclassesr�numpyr/�pandasr*Zsklearn.pipelinerZsklearn.composerZsklearn.imputerZsklearn.preprocessingrr�30src.loggerr�
src.exceptionr	Z	src.utilsr31rrrrrr�<module>s