Regression
framework3.plugins.filters.regression
¶
LogistiRegressionlugin
¶
Bases: BaseFilter
, BasePlugin
A plugin that implements logistic regression using scikit-learn's LogisticRegression.
This plugin wraps the LogisticRegression model from scikit-learn and adapts it to work within the framework3 ecosystem, providing a seamless integration for logistic regression tasks.
Key Features
- Utilizes scikit-learn's LogisticRegression implementation
- Supports customization of maximum iterations and tolerance
- Provides methods for fitting the model and making predictions
- Integrates with framework3's BaseFilter and BasePlugin interfaces
Usage
The LogistiRegressionlugin can be used to perform logistic regression on your data:
import numpy as np
from framework3.base import XYData
from framework3.plugins.filters.regression.logistic_regression import LogistiRegressionlugin
# Create sample data
X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([0, 0, 1, 1])
X_data = XYData(_hash='X_data', _path='/tmp', _value=X)
y_data = XYData(_hash='y_data', _path='/tmp', _value=y)
# Create and fit the LogistiRegressionlugin
log_reg = LogistiRegressionlugin(max_ite=100, tol=1e-4)
log_reg.fit(X_data, y_data)
# Make predictions
X_test = XYData(_hash='X_test', _path='/tmp', _value=np.array([[2.5, 3.5]]))
predictions = log_reg.predict(X_test)
print(predictions.value)
# Access the underlying scikit-learn model
print(log_reg._logistic.coef_)
Attributes:
Name | Type | Description |
---|---|---|
_logistic |
LogisticRegression
|
The underlying scikit-learn LogisticRegression model. |
Methods:
Name | Description |
---|---|
fit |
XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the logistic regression model to the given data. |
predict |
XYData) -> XYData: Make predictions using the fitted logistic regression model. |
Note
This plugin uses scikit-learn's implementation of LogisticRegression, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.
Source code in framework3/plugins/filters/regression/logistic_regression.py
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
__init__(max_ite, tol)
¶
Initialize a new LogistiRegressionlugin instance.
This constructor sets up the LogistiRegressionlugin with the specified parameters and initializes the underlying scikit-learn LogisticRegression model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_ite
|
int
|
Maximum number of iterations for the solver to converge. |
required |
tol
|
float
|
Tolerance for stopping criteria. |
required |
Note
The parameters are passed directly to scikit-learn's LogisticRegression. Refer to scikit-learn's documentation for detailed information on these parameters.
Source code in framework3/plugins/filters/regression/logistic_regression.py
fit(x, y, evaluator=None)
¶
Fit the logistic regression model to the given data.
This method trains the logistic regression model on the provided input features and target values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
XYData
|
The input features. |
required |
y
|
Optional[XYData]
|
The target values. |
required |
evaluator
|
BaseMetric | None
|
An optional evaluator for the model. Not used in this method. |
None
|
Returns:
Type | Description |
---|---|
Optional[float]
|
Optional[float]: The mean accuracy on the given test data and labels. |
Raises:
Type | Description |
---|---|
ValueError
|
If y is None. |
Note
This method uses scikit-learn's fit method internally. The score (mean accuracy) is returned as a measure of how well the model fits the data.
Source code in framework3/plugins/filters/regression/logistic_regression.py
predict(x)
¶
Make predictions using the fitted logistic regression model.
This method uses the trained logistic regression model to predict class labels for new input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
XYData
|
The input features to predict. |
required |
Returns:
Name | Type | Description |
---|---|---|
XYData |
XYData
|
The predicted class labels wrapped in an XYData object. |
Note
This method uses scikit-learn's predict method internally. The predictions are wrapped in an XYData object for consistency with the framework.
Source code in framework3/plugins/filters/regression/logistic_regression.py
logistic_regression
¶
__all__ = ['LogistiRegressionlugin']
module-attribute
¶
LogistiRegressionlugin
¶
Bases: BaseFilter
, BasePlugin
A plugin that implements logistic regression using scikit-learn's LogisticRegression.
This plugin wraps the LogisticRegression model from scikit-learn and adapts it to work within the framework3 ecosystem, providing a seamless integration for logistic regression tasks.
Key Features
- Utilizes scikit-learn's LogisticRegression implementation
- Supports customization of maximum iterations and tolerance
- Provides methods for fitting the model and making predictions
- Integrates with framework3's BaseFilter and BasePlugin interfaces
Usage
The LogistiRegressionlugin can be used to perform logistic regression on your data:
import numpy as np
from framework3.base import XYData
from framework3.plugins.filters.regression.logistic_regression import LogistiRegressionlugin
# Create sample data
X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([0, 0, 1, 1])
X_data = XYData(_hash='X_data', _path='/tmp', _value=X)
y_data = XYData(_hash='y_data', _path='/tmp', _value=y)
# Create and fit the LogistiRegressionlugin
log_reg = LogistiRegressionlugin(max_ite=100, tol=1e-4)
log_reg.fit(X_data, y_data)
# Make predictions
X_test = XYData(_hash='X_test', _path='/tmp', _value=np.array([[2.5, 3.5]]))
predictions = log_reg.predict(X_test)
print(predictions.value)
# Access the underlying scikit-learn model
print(log_reg._logistic.coef_)
Attributes:
Name | Type | Description |
---|---|---|
_logistic |
LogisticRegression
|
The underlying scikit-learn LogisticRegression model. |
Methods:
Name | Description |
---|---|
fit |
XYData, y: Optional[XYData], evaluator: BaseMetric | None = None) -> Optional[float]: Fit the logistic regression model to the given data. |
predict |
XYData) -> XYData: Make predictions using the fitted logistic regression model. |
Note
This plugin uses scikit-learn's implementation of LogisticRegression, which may have its own dependencies and requirements. Ensure that scikit-learn is properly installed and compatible with your environment.
Source code in framework3/plugins/filters/regression/logistic_regression.py
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
|
__init__(max_ite, tol)
¶
Initialize a new LogistiRegressionlugin instance.
This constructor sets up the LogistiRegressionlugin with the specified parameters and initializes the underlying scikit-learn LogisticRegression model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_ite
|
int
|
Maximum number of iterations for the solver to converge. |
required |
tol
|
float
|
Tolerance for stopping criteria. |
required |
Note
The parameters are passed directly to scikit-learn's LogisticRegression. Refer to scikit-learn's documentation for detailed information on these parameters.
Source code in framework3/plugins/filters/regression/logistic_regression.py
fit(x, y, evaluator=None)
¶
Fit the logistic regression model to the given data.
This method trains the logistic regression model on the provided input features and target values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
XYData
|
The input features. |
required |
y
|
Optional[XYData]
|
The target values. |
required |
evaluator
|
BaseMetric | None
|
An optional evaluator for the model. Not used in this method. |
None
|
Returns:
Type | Description |
---|---|
Optional[float]
|
Optional[float]: The mean accuracy on the given test data and labels. |
Raises:
Type | Description |
---|---|
ValueError
|
If y is None. |
Note
This method uses scikit-learn's fit method internally. The score (mean accuracy) is returned as a measure of how well the model fits the data.
Source code in framework3/plugins/filters/regression/logistic_regression.py
predict(x)
¶
Make predictions using the fitted logistic regression model.
This method uses the trained logistic regression model to predict class labels for new input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
XYData
|
The input features to predict. |
required |
Returns:
Name | Type | Description |
---|---|---|
XYData |
XYData
|
The predicted class labels wrapped in an XYData object. |
Note
This method uses scikit-learn's predict method internally. The predictions are wrapped in an XYData object for consistency with the framework.