mlcompare-dev 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Manish Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlcompare-dev
3
+ Version: 0.1.1
4
+ Summary: Compare classification and regression ML models
5
+ Author: Manish Kumar
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: pandas>=2.0.0
11
+ Requires-Dist: numpy>=1.24.0
12
+ Requires-Dist: scikit-learn>=1.4.0
13
+ Requires-Dist: joblib>=1.3.0
14
+ Dynamic: author
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: license
18
+ Dynamic: license-file
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # 🚀 MLCompare
24
+
25
+ **MLCompare** is a beginner-friendly Python library to compare multiple Machine Learning models with just a few lines of code.
26
+
27
+ Instead of writing repetitive code for training and evaluating models, MLCompare automatically trains multiple algorithms, compares their performance, selects the best model, and allows prediction and model saving.
28
+
29
+ ---
30
+
31
+ # ✨ Features
32
+
33
+ - ✅ Automatic Classification & Regression Detection
34
+ - ✅ Train Multiple ML Models
35
+ - ✅ Compare Model Performance
36
+ - ✅ Automatically Select Best Model
37
+ - ✅ Predict Using Best Model
38
+ - ✅ Save & Load Trained Model
39
+ - ✅ Simple Beginner-Friendly API
40
+
41
+ ---
42
+
43
+ # 📦 Installation
44
+
45
+ ```bash
46
+ pip install mlcompare
47
+ ```
48
+
49
+ Or install locally
50
+
51
+ ```bash
52
+ pip install -e .
53
+ ```
54
+
55
+ ---
56
+
57
+ # 📚 Supported Models
58
+
59
+ ## Classification
60
+
61
+ - Logistic Regression
62
+ - K-Nearest Neighbors (KNN)
63
+ - Support Vector Machine (SVM)
64
+ - Decision Tree
65
+ - Random Forest
66
+ - AdaBoost
67
+ - Gradient Boosting
68
+ - Extra Trees
69
+
70
+ ## Regression
71
+
72
+ - Linear Regression
73
+ - Ridge Regression
74
+ - Lasso Regression
75
+ - ElasticNet
76
+ - Decision Tree Regressor
77
+ - Random Forest Regressor
78
+ - Gradient Boosting Regressor
79
+ - Extra Trees Regressor
80
+
81
+ ---
82
+
83
+ # 🚀 Quick Start
84
+
85
+ ```python
86
+ from mlcompare import MLCompare
87
+ import pandas as pd
88
+
89
+ df = pd.read_csv("data.csv")
90
+
91
+ ml = MLCompare(
92
+ data=df,
93
+ target="target"
94
+ )
95
+
96
+ results = ml.compare()
97
+
98
+ print(results)
99
+ ```
100
+
101
+ ---
102
+
103
+ # 🏆 Best Model
104
+
105
+ ```python
106
+ print(ml.best_model_name)
107
+ ```
108
+
109
+ ---
110
+
111
+ # 🔮 Prediction
112
+
113
+ ```python
114
+ new_data = df.drop(columns=["target"]).head()
115
+
116
+ predictions = ml.predict(new_data)
117
+
118
+ print(predictions)
119
+ ```
120
+
121
+ ---
122
+
123
+ # 💾 Save Model
124
+
125
+ ```python
126
+ ml.save("best_model.pkl")
127
+ ```
128
+
129
+ ---
130
+
131
+ # 📂 Load Model
132
+
133
+ ```python
134
+ ml.load("best_model.pkl")
135
+ ```
136
+
137
+ ---
138
+
139
+ # 📊 Example Output
140
+
141
+ | Model | Accuracy |
142
+ |--------|----------|
143
+ | SVM | 0.95 |
144
+ | Random Forest | 0.94 |
145
+ | Extra Trees | 0.93 |
146
+ | Logistic Regression | 0.91 |
147
+
148
+ ---
149
+
150
+ # 📁 Project Structure
151
+
152
+ ```
153
+ mlcompare/
154
+
155
+ ├── core.py
156
+ ├── models.py
157
+ ├── metrics.py
158
+ ├── utils.py
159
+ ├── save.py
160
+ ├── version.py
161
+ └── __init__.py
162
+ ```
163
+
164
+ ---
165
+
166
+ # 🛠 Requirements
167
+
168
+ - Python 3.10+
169
+ - pandas
170
+ - numpy
171
+ - scikit-learn
172
+ - joblib
173
+
174
+ ---
175
+
176
+ # 📌 Roadmap
177
+
178
+ Upcoming Features
179
+
180
+ - Hyperparameter Tuning
181
+ - Cross Validation
182
+ - Feature Importance
183
+ - Confusion Matrix
184
+ - ROC-AUC Score
185
+ - StandardScaler Support
186
+ - Missing Value Handling
187
+ - Categorical Encoding
188
+ - XGBoost
189
+ - LightGBM
190
+ - CatBoost
191
+
192
+ ---
193
+
194
+ # 🤝 Contributing
195
+
196
+ Contributions are welcome!
197
+
198
+ Feel free to open an Issue or submit a Pull Request.
199
+
200
+ ---
201
+
202
+ # 📄 License
203
+
204
+ MIT License
205
+
206
+ ---
207
+
208
+ # 👨‍💻 Author
209
+
210
+ **Manish Kumar**
211
+
212
+ GitHub:
213
+ https://github.com/Developer-Manish007
@@ -0,0 +1,191 @@
1
+ # 🚀 MLCompare
2
+
3
+ **MLCompare** is a beginner-friendly Python library to compare multiple Machine Learning models with just a few lines of code.
4
+
5
+ Instead of writing repetitive code for training and evaluating models, MLCompare automatically trains multiple algorithms, compares their performance, selects the best model, and allows prediction and model saving.
6
+
7
+ ---
8
+
9
+ # ✨ Features
10
+
11
+ - ✅ Automatic Classification & Regression Detection
12
+ - ✅ Train Multiple ML Models
13
+ - ✅ Compare Model Performance
14
+ - ✅ Automatically Select Best Model
15
+ - ✅ Predict Using Best Model
16
+ - ✅ Save & Load Trained Model
17
+ - ✅ Simple Beginner-Friendly API
18
+
19
+ ---
20
+
21
+ # 📦 Installation
22
+
23
+ ```bash
24
+ pip install mlcompare
25
+ ```
26
+
27
+ Or install locally
28
+
29
+ ```bash
30
+ pip install -e .
31
+ ```
32
+
33
+ ---
34
+
35
+ # 📚 Supported Models
36
+
37
+ ## Classification
38
+
39
+ - Logistic Regression
40
+ - K-Nearest Neighbors (KNN)
41
+ - Support Vector Machine (SVM)
42
+ - Decision Tree
43
+ - Random Forest
44
+ - AdaBoost
45
+ - Gradient Boosting
46
+ - Extra Trees
47
+
48
+ ## Regression
49
+
50
+ - Linear Regression
51
+ - Ridge Regression
52
+ - Lasso Regression
53
+ - ElasticNet
54
+ - Decision Tree Regressor
55
+ - Random Forest Regressor
56
+ - Gradient Boosting Regressor
57
+ - Extra Trees Regressor
58
+
59
+ ---
60
+
61
+ # 🚀 Quick Start
62
+
63
+ ```python
64
+ from mlcompare import MLCompare
65
+ import pandas as pd
66
+
67
+ df = pd.read_csv("data.csv")
68
+
69
+ ml = MLCompare(
70
+ data=df,
71
+ target="target"
72
+ )
73
+
74
+ results = ml.compare()
75
+
76
+ print(results)
77
+ ```
78
+
79
+ ---
80
+
81
+ # 🏆 Best Model
82
+
83
+ ```python
84
+ print(ml.best_model_name)
85
+ ```
86
+
87
+ ---
88
+
89
+ # 🔮 Prediction
90
+
91
+ ```python
92
+ new_data = df.drop(columns=["target"]).head()
93
+
94
+ predictions = ml.predict(new_data)
95
+
96
+ print(predictions)
97
+ ```
98
+
99
+ ---
100
+
101
+ # 💾 Save Model
102
+
103
+ ```python
104
+ ml.save("best_model.pkl")
105
+ ```
106
+
107
+ ---
108
+
109
+ # 📂 Load Model
110
+
111
+ ```python
112
+ ml.load("best_model.pkl")
113
+ ```
114
+
115
+ ---
116
+
117
+ # 📊 Example Output
118
+
119
+ | Model | Accuracy |
120
+ |--------|----------|
121
+ | SVM | 0.95 |
122
+ | Random Forest | 0.94 |
123
+ | Extra Trees | 0.93 |
124
+ | Logistic Regression | 0.91 |
125
+
126
+ ---
127
+
128
+ # 📁 Project Structure
129
+
130
+ ```
131
+ mlcompare/
132
+
133
+ ├── core.py
134
+ ├── models.py
135
+ ├── metrics.py
136
+ ├── utils.py
137
+ ├── save.py
138
+ ├── version.py
139
+ └── __init__.py
140
+ ```
141
+
142
+ ---
143
+
144
+ # 🛠 Requirements
145
+
146
+ - Python 3.10+
147
+ - pandas
148
+ - numpy
149
+ - scikit-learn
150
+ - joblib
151
+
152
+ ---
153
+
154
+ # 📌 Roadmap
155
+
156
+ Upcoming Features
157
+
158
+ - Hyperparameter Tuning
159
+ - Cross Validation
160
+ - Feature Importance
161
+ - Confusion Matrix
162
+ - ROC-AUC Score
163
+ - StandardScaler Support
164
+ - Missing Value Handling
165
+ - Categorical Encoding
166
+ - XGBoost
167
+ - LightGBM
168
+ - CatBoost
169
+
170
+ ---
171
+
172
+ # 🤝 Contributing
173
+
174
+ Contributions are welcome!
175
+
176
+ Feel free to open an Issue or submit a Pull Request.
177
+
178
+ ---
179
+
180
+ # 📄 License
181
+
182
+ MIT License
183
+
184
+ ---
185
+
186
+ # 👨‍💻 Author
187
+
188
+ **Manish Kumar**
189
+
190
+ GitHub:
191
+ https://github.com/Developer-Manish007
@@ -0,0 +1,6 @@
1
+ """MLCompare - Compare classification and regression models with common metrics."""
2
+
3
+ from mlcompare.core import MLCompare
4
+ from mlcompare.version import __version__
5
+
6
+ __all__ = ["MLCompare", "__version__"]
@@ -0,0 +1,103 @@
1
+ """
2
+ Main MLCompare class.
3
+ """
4
+
5
+ import pandas as pd
6
+
7
+ from mlcompare.metrics import compute_metrics
8
+ from mlcompare.models import get_models
9
+ from mlcompare.save import save_model
10
+ from mlcompare.utils import detect_problem, split_data, validate_inputs
11
+
12
+
13
+ class MLCompare:
14
+ """
15
+ Compare multiple machine learning models.
16
+ """
17
+
18
+ def __init__(
19
+ self,
20
+ data: pd.DataFrame,
21
+ target: str,
22
+ test_size: float = 0.2,
23
+ random_state: int = 42,
24
+ ):
25
+ self.data = data
26
+ self.target = target
27
+ self.test_size = test_size
28
+ self.random_state = random_state
29
+
30
+ self.problem_type = None
31
+ self.models = None
32
+ self.results = None
33
+ self.best_model = None
34
+ self.best_model_name = None
35
+ self.trained_models = {}
36
+
37
+ def compare(self):
38
+ """
39
+ Train and compare all machine learning models.
40
+ """
41
+
42
+ validate_inputs(self.data, self.target)
43
+
44
+ y = self.data[self.target]
45
+ self.problem_type = detect_problem(y)
46
+
47
+ X_train, X_test, y_train, y_test = split_data(
48
+ self.data,
49
+ self.target,
50
+ self.problem_type,
51
+ self.test_size,
52
+ self.random_state,
53
+ )
54
+
55
+ self.models = get_models(self.problem_type)
56
+
57
+ results = []
58
+ trained_models = {}
59
+
60
+ for name, model in self.models.items():
61
+ model.fit(X_train, y_train)
62
+ y_pred = model.predict(X_test)
63
+ metrics = compute_metrics(self.problem_type, y_test, y_pred)
64
+
65
+ trained_models[name] = model
66
+ results.append({"Model": name, **metrics})
67
+
68
+ self.results = pd.DataFrame(results)
69
+
70
+ if self.problem_type == "classification":
71
+ self.results = self.results.sort_values(
72
+ by="Accuracy",
73
+ ascending=False,
74
+ ).reset_index(drop=True)
75
+ else:
76
+ self.results = self.results.sort_values(
77
+ by="R2 Score",
78
+ ascending=False,
79
+ ).reset_index(drop=True)
80
+
81
+ if not self.results.empty:
82
+ best_name = self.results.iloc[0]["Model"]
83
+ self.best_model_name = best_name
84
+ self.best_model = trained_models[best_name]
85
+
86
+ self.trained_models = trained_models
87
+
88
+ return self.results
89
+
90
+ def predict(self, data):
91
+ """
92
+ Predict using the best trained model.
93
+ """
94
+ if self.best_model is None:
95
+ raise ValueError("No trained model found. Run compare() first.")
96
+
97
+ return self.best_model.predict(data)
98
+
99
+ def save(self, path: str):
100
+ """
101
+ Save the best trained model.
102
+ """
103
+ save_model(self.best_model, path)
@@ -0,0 +1,83 @@
1
+ """
2
+ Evaluation metrics for MLCompare.
3
+ """
4
+
5
+ import numpy as np
6
+
7
+ from sklearn.metrics import (
8
+ accuracy_score,
9
+ precision_score,
10
+ recall_score,
11
+ f1_score,
12
+ mean_absolute_error,
13
+ mean_squared_error,
14
+ r2_score,
15
+ )
16
+
17
+ def compute_metrics(problem_type, y_true, y_pred):
18
+ """
19
+ Compute evaluation metrics.
20
+
21
+ Parameters
22
+ ----------
23
+ problem_type : str
24
+ Either 'classification' or 'regression'.
25
+
26
+ y_true : array-like
27
+ Actual target values.
28
+
29
+ y_pred : array-like
30
+ Predicted target values.
31
+
32
+ Returns
33
+ -------
34
+ dict
35
+ Dictionary containing evaluation metrics.
36
+ """
37
+
38
+ if problem_type == "classification":
39
+
40
+ return {
41
+
42
+ "Accuracy": accuracy_score(y_true, y_pred),
43
+
44
+ "Precision": precision_score(
45
+ y_true,
46
+ y_pred,
47
+ average="weighted",
48
+ zero_division=0,
49
+ ),
50
+
51
+ "Recall": recall_score(
52
+ y_true,
53
+ y_pred,
54
+ average="weighted",
55
+ zero_division=0,
56
+ ),
57
+
58
+ "F1 Score": f1_score(
59
+ y_true,
60
+ y_pred,
61
+ average="weighted",
62
+ zero_division=0,
63
+ ),
64
+ }
65
+ elif problem_type == "regression":
66
+
67
+ mse = mean_squared_error(y_true, y_pred)
68
+
69
+ return {
70
+
71
+ "MAE": mean_absolute_error(y_true, y_pred),
72
+
73
+ "MSE": mse,
74
+
75
+ "RMSE": np.sqrt(mse),
76
+
77
+ "R2 Score": r2_score(y_true, y_pred),
78
+ }
79
+ else:
80
+
81
+ raise ValueError(
82
+ "Problem type must be 'classification' or 'regression'."
83
+ )
@@ -0,0 +1,111 @@
1
+ """
2
+ All machine learning models used in MLCompare.
3
+ """
4
+
5
+ from sklearn.linear_model import (
6
+ LogisticRegression,
7
+ LinearRegression,
8
+ Ridge,
9
+ Lasso,
10
+ ElasticNet,
11
+ )
12
+
13
+ from sklearn.neighbors import KNeighborsClassifier
14
+
15
+ from sklearn.svm import SVC
16
+
17
+ from sklearn.tree import (
18
+ DecisionTreeClassifier,
19
+ DecisionTreeRegressor,
20
+ )
21
+
22
+ from sklearn.ensemble import (
23
+ RandomForestClassifier,
24
+ RandomForestRegressor,
25
+ AdaBoostClassifier,
26
+ GradientBoostingClassifier,
27
+ GradientBoostingRegressor,
28
+ ExtraTreesClassifier,
29
+ ExtraTreesRegressor,
30
+ )
31
+
32
+ RANDOM_STATE = 42
33
+
34
+
35
+ # ----------------------------------------------------------------------------
36
+
37
+ # Classification models
38
+
39
+ classification_models = {
40
+
41
+ "Logistic Regression": LogisticRegression(random_state=RANDOM_STATE),
42
+
43
+ "KNN": KNeighborsClassifier(),
44
+
45
+ "SVM": SVC(random_state=RANDOM_STATE),
46
+
47
+ "Decision Tree": DecisionTreeClassifier(random_state=RANDOM_STATE),
48
+
49
+ "Random Forest": RandomForestClassifier(random_state=RANDOM_STATE),
50
+
51
+ "AdaBoost": AdaBoostClassifier(random_state=RANDOM_STATE),
52
+
53
+ "Gradient Boosting": GradientBoostingClassifier(random_state=RANDOM_STATE),
54
+
55
+ "Extra Trees": ExtraTreesClassifier(random_state=RANDOM_STATE),
56
+
57
+ }
58
+
59
+ # ----------------------------------------------------------------------------
60
+
61
+ # Regression models
62
+
63
+ regression_models = {
64
+
65
+ "Linear Regression": LinearRegression(),
66
+
67
+ "Ridge": Ridge(),
68
+
69
+ "Lasso": Lasso(),
70
+
71
+ "ElasticNet": ElasticNet(),
72
+
73
+ "Decision Tree": DecisionTreeRegressor(random_state=RANDOM_STATE),
74
+
75
+ "Random Forest": RandomForestRegressor(random_state=RANDOM_STATE),
76
+
77
+ "Gradient Boosting": GradientBoostingRegressor(random_state=RANDOM_STATE),
78
+
79
+ "Extra Trees": ExtraTreesRegressor(random_state=RANDOM_STATE),
80
+
81
+ }
82
+
83
+
84
+ # ----------------------------------------------------------------------------
85
+ # Get models
86
+ def get_models(problem_type: str):
87
+ """
88
+ Return machine learning models based on problem type.
89
+
90
+ Parameters
91
+ ----------
92
+ problem_type : str
93
+ Either 'classification' or 'regression'.
94
+
95
+ Returns
96
+ -------
97
+ dict
98
+ Dictionary containing model names and model objects.
99
+ """
100
+
101
+ if problem_type == "classification":
102
+ return classification_models
103
+
104
+ elif problem_type == "regression":
105
+ return regression_models
106
+
107
+ else:
108
+ raise ValueError(
109
+ "Problem type must be 'classification' or 'regression'."
110
+ )
111
+
@@ -0,0 +1,49 @@
1
+ """
2
+ Save and load MLCompare models.
3
+ """
4
+
5
+ import joblib
6
+
7
+
8
+ def save_model(model: object, path: str) -> None:
9
+ """
10
+ Save a trained machine learning model to disk.
11
+
12
+ Parameters
13
+ ----------
14
+ model : object
15
+ Trained machine learning model.
16
+
17
+ path : str
18
+ File path where the model will be saved.
19
+
20
+ Raises
21
+ ------
22
+ ValueError
23
+ If the model is None.
24
+ """
25
+
26
+ if model is None:
27
+ raise ValueError(
28
+ "No trained model found. Run compare() before saving."
29
+ )
30
+
31
+ joblib.dump(model, path)
32
+
33
+
34
+ def load_model(path: str) -> object:
35
+ """
36
+ Load a trained machine learning model from disk.
37
+
38
+ Parameters
39
+ ----------
40
+ path : str
41
+ Path to the saved model.
42
+
43
+ Returns
44
+ -------
45
+ object
46
+ Loaded machine learning model.
47
+ """
48
+
49
+ return joblib.load(path)
@@ -0,0 +1,123 @@
1
+ """
2
+ Utility functions for MLCompare.
3
+ """
4
+
5
+ import pandas as pd
6
+
7
+ from sklearn.model_selection import train_test_split
8
+
9
+
10
+ # Validate Inputs()
11
+ ## ----------------------------------------------------------------------------
12
+ def validate_inputs(data, target=None):
13
+ """
14
+ Validate input dataset and target values.
15
+
16
+ This function supports two calling patterns:
17
+ - validate_inputs(data_frame, target_column_name)
18
+ - validate_inputs(features, target_series)
19
+ """
20
+
21
+ if isinstance(data, pd.DataFrame) and isinstance(target, str):
22
+ if data.empty:
23
+ raise ValueError("Input DataFrame is empty.")
24
+
25
+ if target not in data.columns:
26
+ raise ValueError(f"Target column '{target}' not found.")
27
+
28
+ if data[target].isnull().all():
29
+ raise ValueError("Target column contains only missing values.")
30
+
31
+ return data.drop(columns=[target]), data[target]
32
+
33
+ if target is None:
34
+ raise TypeError("target must be provided.")
35
+
36
+ X = data
37
+ y = pd.Series(target)
38
+
39
+ if isinstance(X, pd.DataFrame) and X.empty:
40
+ raise ValueError("Input DataFrame is empty.")
41
+
42
+ if y.empty:
43
+ raise ValueError("Target values are empty.")
44
+
45
+ if y.isnull().all():
46
+ raise ValueError("Target column contains only missing values.")
47
+
48
+ return X, y
49
+
50
+
51
+ # 2️⃣ detect_problem()
52
+ def detect_problem(y):
53
+ """
54
+ Automatically detect classification or regression.
55
+ """
56
+
57
+ if (
58
+ y.dtype == "object"
59
+ or str(y.dtype) == "category"
60
+ or y.dtype == "bool"
61
+ ):
62
+ return "classification"
63
+
64
+ elif pd.api.types.is_integer_dtype(y):
65
+ if y.nunique() <= 20:
66
+ return "classification"
67
+ return "regression"
68
+
69
+ elif pd.api.types.is_float_dtype(y):
70
+ return "regression"
71
+
72
+ else:
73
+ raise ValueError("Unable to detect problem type.")
74
+
75
+
76
+ # 3️⃣ split_data()
77
+ def split_data(
78
+ data,
79
+ target=None,
80
+ problem_type=None,
81
+ test_size=0.2,
82
+ random_state=42,
83
+ ):
84
+ """
85
+ Split dataset into train and test sets.
86
+
87
+ Supports both the convenience form with a DataFrame and target column name,
88
+ and the direct form with features X and target values y.
89
+ """
90
+
91
+ if isinstance(problem_type, str):
92
+ X = data.drop(columns=[target])
93
+ y = data[target]
94
+ split_test_size = test_size
95
+ split_random_state = random_state
96
+ detected_problem = problem_type
97
+ else:
98
+ X = data
99
+ y = target
100
+ split_test_size = problem_type
101
+ split_random_state = test_size
102
+ detected_problem = detect_problem(y)
103
+
104
+ stratify = y if detected_problem == "classification" else None
105
+
106
+ try:
107
+ return train_test_split(
108
+ X,
109
+ y,
110
+ test_size=split_test_size,
111
+ random_state=split_random_state,
112
+ stratify=stratify,
113
+ )
114
+ except ValueError as exc:
115
+ if stratify is not None and "least populated classes" in str(exc):
116
+ return train_test_split(
117
+ X,
118
+ y,
119
+ test_size=split_test_size,
120
+ random_state=split_random_state,
121
+ stratify=None,
122
+ )
123
+ raise
@@ -0,0 +1,3 @@
1
+ """Package version."""
2
+
3
+ __version__ = "0.1.1"
@@ -0,0 +1,213 @@
1
+ Metadata-Version: 2.4
2
+ Name: mlcompare-dev
3
+ Version: 0.1.1
4
+ Summary: Compare classification and regression ML models
5
+ Author: Manish Kumar
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: pandas>=2.0.0
11
+ Requires-Dist: numpy>=1.24.0
12
+ Requires-Dist: scikit-learn>=1.4.0
13
+ Requires-Dist: joblib>=1.3.0
14
+ Dynamic: author
15
+ Dynamic: description
16
+ Dynamic: description-content-type
17
+ Dynamic: license
18
+ Dynamic: license-file
19
+ Dynamic: requires-dist
20
+ Dynamic: requires-python
21
+ Dynamic: summary
22
+
23
+ # 🚀 MLCompare
24
+
25
+ **MLCompare** is a beginner-friendly Python library to compare multiple Machine Learning models with just a few lines of code.
26
+
27
+ Instead of writing repetitive code for training and evaluating models, MLCompare automatically trains multiple algorithms, compares their performance, selects the best model, and allows prediction and model saving.
28
+
29
+ ---
30
+
31
+ # ✨ Features
32
+
33
+ - ✅ Automatic Classification & Regression Detection
34
+ - ✅ Train Multiple ML Models
35
+ - ✅ Compare Model Performance
36
+ - ✅ Automatically Select Best Model
37
+ - ✅ Predict Using Best Model
38
+ - ✅ Save & Load Trained Model
39
+ - ✅ Simple Beginner-Friendly API
40
+
41
+ ---
42
+
43
+ # 📦 Installation
44
+
45
+ ```bash
46
+ pip install mlcompare
47
+ ```
48
+
49
+ Or install locally
50
+
51
+ ```bash
52
+ pip install -e .
53
+ ```
54
+
55
+ ---
56
+
57
+ # 📚 Supported Models
58
+
59
+ ## Classification
60
+
61
+ - Logistic Regression
62
+ - K-Nearest Neighbors (KNN)
63
+ - Support Vector Machine (SVM)
64
+ - Decision Tree
65
+ - Random Forest
66
+ - AdaBoost
67
+ - Gradient Boosting
68
+ - Extra Trees
69
+
70
+ ## Regression
71
+
72
+ - Linear Regression
73
+ - Ridge Regression
74
+ - Lasso Regression
75
+ - ElasticNet
76
+ - Decision Tree Regressor
77
+ - Random Forest Regressor
78
+ - Gradient Boosting Regressor
79
+ - Extra Trees Regressor
80
+
81
+ ---
82
+
83
+ # 🚀 Quick Start
84
+
85
+ ```python
86
+ from mlcompare import MLCompare
87
+ import pandas as pd
88
+
89
+ df = pd.read_csv("data.csv")
90
+
91
+ ml = MLCompare(
92
+ data=df,
93
+ target="target"
94
+ )
95
+
96
+ results = ml.compare()
97
+
98
+ print(results)
99
+ ```
100
+
101
+ ---
102
+
103
+ # 🏆 Best Model
104
+
105
+ ```python
106
+ print(ml.best_model_name)
107
+ ```
108
+
109
+ ---
110
+
111
+ # 🔮 Prediction
112
+
113
+ ```python
114
+ new_data = df.drop(columns=["target"]).head()
115
+
116
+ predictions = ml.predict(new_data)
117
+
118
+ print(predictions)
119
+ ```
120
+
121
+ ---
122
+
123
+ # 💾 Save Model
124
+
125
+ ```python
126
+ ml.save("best_model.pkl")
127
+ ```
128
+
129
+ ---
130
+
131
+ # 📂 Load Model
132
+
133
+ ```python
134
+ ml.load("best_model.pkl")
135
+ ```
136
+
137
+ ---
138
+
139
+ # 📊 Example Output
140
+
141
+ | Model | Accuracy |
142
+ |--------|----------|
143
+ | SVM | 0.95 |
144
+ | Random Forest | 0.94 |
145
+ | Extra Trees | 0.93 |
146
+ | Logistic Regression | 0.91 |
147
+
148
+ ---
149
+
150
+ # 📁 Project Structure
151
+
152
+ ```
153
+ mlcompare/
154
+
155
+ ├── core.py
156
+ ├── models.py
157
+ ├── metrics.py
158
+ ├── utils.py
159
+ ├── save.py
160
+ ├── version.py
161
+ └── __init__.py
162
+ ```
163
+
164
+ ---
165
+
166
+ # 🛠 Requirements
167
+
168
+ - Python 3.10+
169
+ - pandas
170
+ - numpy
171
+ - scikit-learn
172
+ - joblib
173
+
174
+ ---
175
+
176
+ # 📌 Roadmap
177
+
178
+ Upcoming Features
179
+
180
+ - Hyperparameter Tuning
181
+ - Cross Validation
182
+ - Feature Importance
183
+ - Confusion Matrix
184
+ - ROC-AUC Score
185
+ - StandardScaler Support
186
+ - Missing Value Handling
187
+ - Categorical Encoding
188
+ - XGBoost
189
+ - LightGBM
190
+ - CatBoost
191
+
192
+ ---
193
+
194
+ # 🤝 Contributing
195
+
196
+ Contributions are welcome!
197
+
198
+ Feel free to open an Issue or submit a Pull Request.
199
+
200
+ ---
201
+
202
+ # 📄 License
203
+
204
+ MIT License
205
+
206
+ ---
207
+
208
+ # 👨‍💻 Author
209
+
210
+ **Manish Kumar**
211
+
212
+ GitHub:
213
+ https://github.com/Developer-Manish007
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ mlcompare/__init__.py
5
+ mlcompare/core.py
6
+ mlcompare/metrics.py
7
+ mlcompare/models.py
8
+ mlcompare/save.py
9
+ mlcompare/utils.py
10
+ mlcompare/version.py
11
+ mlcompare_dev.egg-info/PKG-INFO
12
+ mlcompare_dev.egg-info/SOURCES.txt
13
+ mlcompare_dev.egg-info/dependency_links.txt
14
+ mlcompare_dev.egg-info/requires.txt
15
+ mlcompare_dev.egg-info/top_level.txt
@@ -0,0 +1,4 @@
1
+ pandas>=2.0.0
2
+ numpy>=1.24.0
3
+ scikit-learn>=1.4.0
4
+ joblib>=1.3.0
@@ -0,0 +1 @@
1
+ mlcompare
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,22 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", encoding="utf-8") as f:
4
+ long_description = f.read()
5
+
6
+ setup(
7
+ name="mlcompare-dev",
8
+ version="0.1.1",
9
+ author="Manish Kumar",
10
+ description="Compare classification and regression ML models",
11
+ long_description=long_description,
12
+ license="MIT",
13
+ long_description_content_type="text/markdown",
14
+ packages=find_packages(),
15
+ install_requires=[
16
+ "pandas>=2.0.0",
17
+ "numpy>=1.24.0",
18
+ "scikit-learn>=1.4.0",
19
+ "joblib>=1.3.0",
20
+ ],
21
+ python_requires=">=3.10",
22
+ )