Package: datret
DatRet: Tensorflow implementation for structured tabular dataRete neurale per la previsione diDati tabulari. (it.)What is it?A simple implementation of a deep neural network architecture for tabular data with automatic layer-by-layer reduction in the number of neurons and functionality similar to classical machine learning methods.Main Featuressimplicity and ease of use. Fit and Predict et Voila!quick adjustment of model parametersGPU supporthigh prediction accuracysupport for multilabel classificationTensorflow under the hood;)Where to get it?The source code is currently hosted on GitHub at:GitHub - AbdualimovTP/datret: Tensorflow implementation for structured tabular dataBinary installers for the latest released version are available at thePython
Package Index (PyPI)# PyPIpipinstalldatretDependenciesTensorflow - An open-source library primarily for deep learning applicationsNumPy - Adds support for large, multi-dimensional arrays, matrices and high-level mathematical functions to operate on these arrays[Pandas - Python data analysis toolkit](pandas documentation — pandas 1.5.2 documentation)Scikit-Learn - machine learning in PythonQuick startTraining and prediction of the model is implemented as in scikit-learn. Prepare your test and train set and run the fit. Support for automatic data normalization for neural networks.NB! Don't forget to install the dependencies before using the model. You will need Tensorflow, Numpy, Pandas and Scikit-Learn installed.NB! No need to do one-hot encoding of predictive features. The model will do automatically.# load libraryfromdatret.datretimportDatRetClassifier,DatRetRegressor,DatRetMultilabelClassifier# prepare train, test split. As in sklearn.# for exampleX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=i)# Call the regressor or classifier and train the model.DR=DatRetClassifier()# DatRetRegressor works on the same principleDR.fit(X_train,y_train)# predict the actual label (or class) over a new set of data.DR_predict=DR.predict(X_test)# predict the class probabilities for each data point.DR_predict_proba=DR.predict_proba(X_test)# Missing in DatRetRegressor, DatRetMultilabelClassifierCustom model optionsParameters:epoch:int, default = 30. Number of epochs to train the model.optimizer:string (name of optimizer) or optimizer instance. Seetf.keras.optimizers, default  =Adam(learning_rate=0.001). On DatRetRegressor defaut learning rate = 0.01. Built-in tensorflow optimizer classes.loss:Loss function. May be a string (name of loss function). Seetf.keras.losses, default for DatRetClassifier =CategoricalCrossentropy(), for DatRetRegressor =MeanSquaredError(). Built-in loss functions.verbose:'auto', 0, 1, or 2, default=0. Verbosity mode. 0 = silent, 1 = progress bar, 2 = one line per epoch. 'auto' defaults to 1 for most cases, but 2 when used with ParameterServerStrategy=0.number_neurons:int, default = 500. The number of layers in the first fully connected layer. Subsequent layers are generated automatically with half as many neurons.validation_split:Float between 0 and 1, default = 0. Fraction of the training data to be used as validation data. The model will set apart this fraction of the training data, will not train on it, and will evaluate the loss and any model metrics on this data at the end of each epoch.batch_size:int, default =1. Number of samples per gradient update. Steps_per_epoch s calculated automatically,X_train.shape[0] // batch_sizeshuffle:True or False, default = True. This argument is ignored whenxis a generator or an object of tf.data.Dataset. 'batch' is a special option for dealing with the limitations of HDF5 data; it shuffles in batch-sized chunks.callback:[], default =[EarlyStopping(monitor='loss', mode='auto', patience=7, verbose=1), ReduceLROnPlateau(monitor='loss', factor=0.2, patience=3, min_lr=0.00001, verbose=1)].Callbacks: utilities called at certain points during model training.Adjustablefitmethod parametersParameters:normalize:True or False ,default True. Automatic normalization of input data. UsedMinMaxScaler.Example:# load libraryimporttensorflowastffromtensorflow.keras.layersimport*fromtensorflow.keras.modelsimportModelfromtensorflow.keras.optimizersimportAdam,Nadamfromtensorflow.keras.callbacksimportEarlyStopping,ReduceLROnPlateaufromtensorflow.keras.lossesimportCategoricalCrossentropy,MeanSquaredError,BinaryCrossentropyfromdatret.datretimportDatRetClassifier,DatRetRegressor,DatRetMultilabelClassifier# prepare train, test split. As in sklearn.# for exampleX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=i)# Call the regressor or classifier and train the model.DR=DatRetClassifier(epoch=50,optimizer=Nadam(learning_rate=0.001),loss=BinaryCrossentropy(),verbose=1,number_neurons=1000,validation_split=0.1,batch_size=100,shuffle=True,callback=[])DR.fit(X_train,y_train,normalize=True)# predict the actual label (or class) over a new set of data.DR_predict=DR.predict(X_test)# predict the class probabilities for each data point.DR_predict_proba=DR.predict_proba(X_test)Model architectureAs an example, when usingnumber_neurons = 500input neurons and 2 predictable classes, the model will automatically have this architecture.Model:"DatRet with number_neurons = 500"_________________________________________________________________Layer(type)OutputShapeParam#=================================================================input_1(InputLayer)[(None,X_train.shape[0)]0dense(Dense)(None,500)150500dense_1(Dense)(None,250)125250dense_2(Dense)(None,125)31375dense_3(Dense)(None,62)7812dense_4(Dense)(None,31)1953dense_5(Dense)(None,15)480dense_6(Dense)(None,7)112dense_7(Dense)(None,3)24dense_8(Dense)(None,2)8(2predictableclasses)=================================================================Totalparams:317,514Trainableparams:317,514Non-trainableparams:0_________________________________________________________________Comparison of accuracy with classical machine learning methodsDatRetClassifierTo assess the accuracy of the classifier, we will usePima Indians Diabetes Database | Kaggle. Comparable metricRocAucScore. We will compare DatRet with RandomForest and CatBoost out "of the box".10%20%30%40%50%60%RandomForest0.790.810.810.790.820.82CatBoost0.780.820.820.80.810.82DatRet0.790.840.820.810.840.81DatRetRegressorTo assess the accuracy of the regressor, we will useMedical Cost Personal Datasets | Kaggle. Comparable metricRoot Mean Square Error. We will compare DatRet with RandomForest and CatBoost out "of the box".10%20%30%40%50%60%RandomForest573652954777495649044793CatBoost573252514664498650444989DatRet586051734610492750475780