near_model.LogisticRegression
Có thể bạn quan tâm
- Install
- User Guide
- API
- Examples
- Community
- Getting Started
- Release History
- Glossary
- Development
- FAQ
- Support
- Related Projects
- Roadmap
- Governance
- About us
- GitHub
Section Navigation
- sklearn
- config_context
- get_config
- set_config
- show_versions
- sklearn.base
- BaseEstimator
- BiclusterMixin
- ClassNamePrefixFeaturesOutMixin
- ClassifierMixin
- ClusterMixin
- DensityMixin
- MetaEstimatorMixin
- OneToOneFeatureMixin
- OutlierMixin
- RegressorMixin
- TransformerMixin
- clone
- is_classifier
- is_clusterer
- is_regressor
- is_outlier_detector
- sklearn.calibration
- CalibratedClassifierCV
- calibration_curve
- CalibrationDisplay
- sklearn.cluster
- AffinityPropagation
- AgglomerativeClustering
- Birch
- BisectingKMeans
- DBSCAN
- FeatureAgglomeration
- HDBSCAN
- KMeans
- MeanShift
- MiniBatchKMeans
- OPTICS
- SpectralBiclustering
- SpectralClustering
- SpectralCoclustering
- affinity_propagation
- cluster_optics_dbscan
- cluster_optics_xi
- compute_optics_graph
- dbscan
- estimate_bandwidth
- k_means
- kmeans_plusplus
- mean_shift
- spectral_clustering
- ward_tree
- sklearn.compose
- ColumnTransformer
- TransformedTargetRegressor
- make_column_selector
- make_column_transformer
- sklearn.covariance
- EllipticEnvelope
- EmpiricalCovariance
- GraphicalLasso
- GraphicalLassoCV
- LedoitWolf
- MinCovDet
- OAS
- ShrunkCovariance
- empirical_covariance
- graphical_lasso
- ledoit_wolf
- ledoit_wolf_shrinkage
- oas
- shrunk_covariance
- sklearn.cross_decomposition
- CCA
- PLSCanonical
- PLSRegression
- PLSSVD
- sklearn.datasets
- clear_data_home
- dump_svmlight_file
- fetch_20newsgroups
- fetch_20newsgroups_vectorized
- fetch_california_housing
- fetch_covtype
- fetch_file
- fetch_kddcup99
- fetch_lfw_pairs
- fetch_lfw_people
- fetch_olivetti_faces
- fetch_openml
- fetch_rcv1
- fetch_species_distributions
- get_data_home
- load_breast_cancer
- load_diabetes
- load_digits
- load_files
- load_iris
- load_linnerud
- load_sample_image
- load_sample_images
- load_svmlight_file
- load_svmlight_files
- load_wine
- make_biclusters
- make_blobs
- make_checkerboard
- make_circles
- make_classification
- make_friedman1
- make_friedman2
- make_friedman3
- make_gaussian_quantiles
- make_hastie_10_2
- make_low_rank_matrix
- make_moons
- make_multilabel_classification
- make_regression
- make_s_curve
- make_sparse_coded_signal
- make_sparse_spd_matrix
- make_sparse_uncorrelated
- make_spd_matrix
- make_swiss_roll
- sklearn.decomposition
- DictionaryLearning
- FactorAnalysis
- FastICA
- IncrementalPCA
- KernelPCA
- LatentDirichletAllocation
- MiniBatchDictionaryLearning
- MiniBatchNMF
- MiniBatchSparsePCA
- NMF
- PCA
- SparseCoder
- SparsePCA
- TruncatedSVD
- dict_learning
- dict_learning_online
- fastica
- non_negative_factorization
- sparse_encode
- sklearn.discriminant_analysis
- LinearDiscriminantAnalysis
- QuadraticDiscriminantAnalysis
- sklearn.dummy
- DummyClassifier
- DummyRegressor
- sklearn.ensemble
- AdaBoostClassifier
- AdaBoostRegressor
- BaggingClassifier
- BaggingRegressor
- ExtraTreesClassifier
- ExtraTreesRegressor
- GradientBoostingClassifier
- GradientBoostingRegressor
- HistGradientBoostingClassifier
- HistGradientBoostingRegressor
- IsolationForest
- RandomForestClassifier
- RandomForestRegressor
- RandomTreesEmbedding
- StackingClassifier
- StackingRegressor
- VotingClassifier
- VotingRegressor
- sklearn.exceptions
- ConvergenceWarning
- DataConversionWarning
- DataDimensionalityWarning
- EfficiencyWarning
- FitFailedWarning
- InconsistentVersionWarning
- NotFittedError
- UndefinedMetricWarning
- EstimatorCheckFailedWarning
- sklearn.experimental
- enable_halving_search_cv
- enable_iterative_imputer
- sklearn.feature_extraction
- DictVectorizer
- FeatureHasher
- PatchExtractor
- extract_patches_2d
- grid_to_graph
- img_to_graph
- reconstruct_from_patches_2d
- CountVectorizer
- HashingVectorizer
- TfidfTransformer
- TfidfVectorizer
- sklearn.feature_selection
- GenericUnivariateSelect
- RFE
- RFECV
- SelectFdr
- SelectFpr
- SelectFromModel
- SelectFwe
- SelectKBest
- SelectPercentile
- SelectorMixin
- SequentialFeatureSelector
- VarianceThreshold
- chi2
- f_classif
- f_regression
- mutual_info_classif
- mutual_info_regression
- r_regression
- sklearn.frozen
- FrozenEstimator
- sklearn.gaussian_process
- GaussianProcessClassifier
- GaussianProcessRegressor
- CompoundKernel
- ConstantKernel
- DotProduct
- ExpSineSquared
- Exponentiation
- Hyperparameter
- Kernel
- Matern
- PairwiseKernel
- Product
- RBF
- RationalQuadratic
- Sum
- WhiteKernel
- sklearn.impute
- IterativeImputer
- KNNImputer
- MissingIndicator
- SimpleImputer
- sklearn.inspection
- partial_dependence
- permutation_importance
- DecisionBoundaryDisplay
- PartialDependenceDisplay
- sklearn.isotonic
- IsotonicRegression
- check_increasing
- isotonic_regression
- sklearn.kernel_approximation
- AdditiveChi2Sampler
- Nystroem
- PolynomialCountSketch
- RBFSampler
- SkewedChi2Sampler
- sklearn.kernel_ridge
- KernelRidge
- sklearn.linear_model
- LogisticRegression
- LogisticRegressionCV
- PassiveAggressiveClassifier
- Perceptron
- RidgeClassifier
- RidgeClassifierCV
- SGDClassifier
- SGDOneClassSVM
- LinearRegression
- Ridge
- RidgeCV
- SGDRegressor
- ElasticNet
- ElasticNetCV
- Lars
- LarsCV
- Lasso
- LassoCV
- LassoLars
- LassoLarsCV
- LassoLarsIC
- OrthogonalMatchingPursuit
- OrthogonalMatchingPursuitCV
- ARDRegression
- BayesianRidge
- MultiTaskElasticNet
- MultiTaskElasticNetCV
- MultiTaskLasso
- MultiTaskLassoCV
- HuberRegressor
- QuantileRegressor
- RANSACRegressor
- TheilSenRegressor
- GammaRegressor
- PoissonRegressor
- TweedieRegressor
- PassiveAggressiveRegressor
- enet_path
- lars_path
- lars_path_gram
- lasso_path
- orthogonal_mp
- orthogonal_mp_gram
- ridge_regression
- sklearn.manifold
- ClassicalMDS
- Isomap
- LocallyLinearEmbedding
- MDS
- SpectralEmbedding
- TSNE
- locally_linear_embedding
- smacof
- spectral_embedding
- trustworthiness
- sklearn.metrics
- check_scoring
- get_scorer
- get_scorer_names
- make_scorer
- accuracy_score
- auc
- average_precision_score
- balanced_accuracy_score
- brier_score_loss
- class_likelihood_ratios
- classification_report
- cohen_kappa_score
- confusion_matrix
- confusion_matrix_at_thresholds
- d2_brier_score
- d2_log_loss_score
- dcg_score
- det_curve
- f1_score
- fbeta_score
- hamming_loss
- hinge_loss
- jaccard_score
- log_loss
- matthews_corrcoef
- multilabel_confusion_matrix
- ndcg_score
- precision_recall_curve
- precision_recall_fscore_support
- precision_score
- recall_score
- roc_auc_score
- roc_curve
- top_k_accuracy_score
- zero_one_loss
- d2_absolute_error_score
- d2_pinball_score
- d2_tweedie_score
- explained_variance_score
- max_error
- mean_absolute_error
- mean_absolute_percentage_error
- mean_gamma_deviance
- mean_pinball_loss
- mean_poisson_deviance
- mean_squared_error
- mean_squared_log_error
- mean_tweedie_deviance
- median_absolute_error
- r2_score
- root_mean_squared_error
- root_mean_squared_log_error
- coverage_error
- label_ranking_average_precision_score
- label_ranking_loss
- adjusted_mutual_info_score
- adjusted_rand_score
- calinski_harabasz_score
- contingency_matrix
- pair_confusion_matrix
- completeness_score
- davies_bouldin_score
- fowlkes_mallows_score
- homogeneity_completeness_v_measure
- homogeneity_score
- mutual_info_score
- normalized_mutual_info_score
- rand_score
- silhouette_samples
- silhouette_score
- v_measure_score
- consensus_score
- DistanceMetric
- additive_chi2_kernel
- chi2_kernel
- cosine_distances
- cosine_similarity
- distance_metrics
- euclidean_distances
- haversine_distances
- kernel_metrics
- laplacian_kernel
- linear_kernel
- manhattan_distances
- nan_euclidean_distances
- paired_cosine_distances
- paired_distances
- paired_euclidean_distances
- paired_manhattan_distances
- pairwise_kernels
- polynomial_kernel
- rbf_kernel
- sigmoid_kernel
- pairwise_distances
- pairwise_distances_argmin
- pairwise_distances_argmin_min
- pairwise_distances_chunked
- ConfusionMatrixDisplay
- DetCurveDisplay
- PrecisionRecallDisplay
- PredictionErrorDisplay
- RocCurveDisplay
- sklearn.mixture
- BayesianGaussianMixture
- GaussianMixture
- sklearn.model_selection
- GroupKFold
- GroupShuffleSplit
- KFold
- LeaveOneGroupOut
- LeaveOneOut
- LeavePGroupsOut
- LeavePOut
- PredefinedSplit
- RepeatedKFold
- RepeatedStratifiedKFold
- ShuffleSplit
- StratifiedGroupKFold
- StratifiedKFold
- StratifiedShuffleSplit
- TimeSeriesSplit
- check_cv
- train_test_split
- GridSearchCV
- HalvingGridSearchCV
- HalvingRandomSearchCV
- ParameterGrid
- ParameterSampler
- RandomizedSearchCV
- FixedThresholdClassifier
- TunedThresholdClassifierCV
- cross_val_predict
- cross_val_score
- cross_validate
- learning_curve
- permutation_test_score
- validation_curve
- LearningCurveDisplay
- ValidationCurveDisplay
- sklearn.multiclass
- OneVsOneClassifier
- OneVsRestClassifier
- OutputCodeClassifier
- sklearn.multioutput
- ClassifierChain
- MultiOutputClassifier
- MultiOutputRegressor
- RegressorChain
- sklearn.naive_bayes
- BernoulliNB
- CategoricalNB
- ComplementNB
- GaussianNB
- MultinomialNB
- sklearn.neighbors
- BallTree
- KDTree
- KNeighborsClassifier
- KNeighborsRegressor
- KNeighborsTransformer
- KernelDensity
- LocalOutlierFactor
- NearestCentroid
- NearestNeighbors
- NeighborhoodComponentsAnalysis
- RadiusNeighborsClassifier
- RadiusNeighborsRegressor
- RadiusNeighborsTransformer
- kneighbors_graph
- radius_neighbors_graph
- sort_graph_by_row_values
- sklearn.neural_network
- BernoulliRBM
- MLPClassifier
- MLPRegressor
- sklearn.pipeline
- FeatureUnion
- Pipeline
- make_pipeline
- make_union
- sklearn.preprocessing
- Binarizer
- FunctionTransformer
- KBinsDiscretizer
- KernelCenterer
- LabelBinarizer
- LabelEncoder
- MaxAbsScaler
- MinMaxScaler
- MultiLabelBinarizer
- Normalizer
- OneHotEncoder
- OrdinalEncoder
- PolynomialFeatures
- PowerTransformer
- QuantileTransformer
- RobustScaler
- SplineTransformer
- StandardScaler
- TargetEncoder
- add_dummy_feature
- binarize
- label_binarize
- maxabs_scale
- minmax_scale
- normalize
- power_transform
- quantile_transform
- robust_scale
- scale
- sklearn.random_projection
- GaussianRandomProjection
- SparseRandomProjection
- johnson_lindenstrauss_min_dim
- sklearn.semi_supervised
- LabelPropagation
- LabelSpreading
- SelfTrainingClassifier
- sklearn.svm
- LinearSVC
- LinearSVR
- NuSVC
- NuSVR
- OneClassSVM
- SVC
- SVR
- l1_min_c
- sklearn.tree
- DecisionTreeClassifier
- DecisionTreeRegressor
- ExtraTreeClassifier
- ExtraTreeRegressor
- export_graphviz
- export_text
- plot_tree
- sklearn.utils
- Bunch
- _safe_indexing
- as_float_array
- assert_all_finite
- deprecated
- estimator_html_repr
- gen_batches
- gen_even_slices
- indexable
- murmurhash3_32
- resample
- safe_mask
- safe_sqr
- shuffle
- Tags
- InputTags
- TargetTags
- ClassifierTags
- RegressorTags
- TransformerTags
- get_tags
- check_X_y
- check_array
- check_consistent_length
- check_random_state
- check_scalar
- check_is_fitted
- check_memory
- check_symmetric
- column_or_1d
- has_fit_parameter
- validate_data
- available_if
- compute_class_weight
- compute_sample_weight
- is_multilabel
- type_of_target
- unique_labels
- density
- fast_logdet
- randomized_range_finder
- randomized_svd
- safe_sparse_dot
- weighted_mode
- incr_mean_variance_axis
- inplace_column_scale
- inplace_csr_column_scale
- inplace_row_scale
- inplace_swap_column
- inplace_swap_row
- mean_variance_axis
- inplace_csr_row_normalize_l1
- inplace_csr_row_normalize_l2
- single_source_shortest_path_length
- sample_without_replacement
- min_pos
- MetadataRequest
- MetadataRouter
- MethodMapping
- get_routing_for_object
- process_routing
- all_displays
- all_estimators
- all_functions
- check_estimator
- parametrize_with_checks
- estimator_checks_generator
- Parallel
- delayed
- API Reference
- sklearn.linear_model
- LogisticRegression
Logistic Regression (aka logit, MaxEnt) classifier.
This class implements regularized logistic regression using a set of available solvers. Note that regularization is applied by default. It can handle both dense and sparse input X. Use C-ordered arrays or CSR matrices containing 64-bit floats for optimal performance; any other input format will be converted (and copied).
The solvers ‘lbfgs’, ‘newton-cg’, ‘newton-cholesky’ and ‘sag’ support only L2 regularization with primal formulation, or no regularization. The ‘liblinear’ solver supports both L1 and L2 regularization (but not both, i.e. elastic-net), with a dual formulation only for the L2 penalty. The Elastic-Net (combination of L1 and L2) regularization is only supported by the ‘saga’ solver.
For multiclass problems (whenever n_classes >= 3), all solvers except ‘liblinear’ optimize the (penalized) multinomial loss. ‘liblinear’ only handles binary classification but can be extended to handle multiclass by using OneVsRestClassifier.
Read more in the User Guide.
Parameters: penalty{‘l1’, ‘l2’, ‘elasticnet’, None}, default=’l2’Specify the norm of the penalty:
None: no penalty is added;
'l2': add a L2 penalty term and it is the default choice;
'l1': add a L1 penalty term;
'elasticnet': both L1 and L2 penalty terms are added.
Warning
Some penalties may not work with some solvers. See the parameter solver below, to know the compatibility between the penalty and solver.
Added in version 0.19: l1 penalty with SAGA solver (allowing ‘multinomial’ + L1)
Deprecated since version 1.8: penalty was deprecated in version 1.8 and will be removed in 1.10. Use l1_ratio instead. l1_ratio=0 for penalty='l2', l1_ratio=1 for penalty='l1' and l1_ratio set to any float between 0 and 1 for 'penalty='elasticnet'.
Cfloat, default=1.0Inverse of regularization strength; must be a positive float. Like in support vector machines, smaller values specify stronger regularization. C=np.inf results in unpenalized logistic regression. For a visual example on the effect of tuning the C parameter with an L1 penalty, see: Regularization path of L1- Logistic Regression.
l1_ratiofloat, default=0.0The Elastic-Net mixing parameter, with 0 <= l1_ratio <= 1. Setting l1_ratio=1 gives a pure L1-penalty, setting l1_ratio=0 a pure L2-penalty. Any value between 0 and 1 gives an Elastic-Net penalty of the form l1_ratio * L1 + (1 - l1_ratio) * L2.
Warning
Certain values of l1_ratio, i.e. some penalties, may not work with some solvers. See the parameter solver below, to know the compatibility between the penalty and solver.
Changed in version 1.8: Default value changed from None to 0.0.
Deprecated since version 1.8: None is deprecated and will be removed in version 1.10. Always use l1_ratio to specify the penalty type.
dualbool, default=FalseDual (constrained) or primal (regularized, see also this equation) formulation. Dual formulation is only implemented for l2 penalty with liblinear solver. Prefer dual=False when n_samples > n_features.
tolfloat, default=1e-4Tolerance for stopping criteria.
fit_interceptbool, default=TrueSpecifies if a constant (a.k.a. bias or intercept) should be added to the decision function.
intercept_scalingfloat, default=1Useful only when the solver liblinear is used and self.fit_intercept is set to True. In this case, x becomes [x, self.intercept_scaling], i.e. a “synthetic” feature with constant value equal to intercept_scaling is appended to the instance vector. The intercept becomes intercept_scaling * synthetic_feature_weight.
Note
The synthetic feature weight is subject to L1 or L2 regularization as all other features. To lessen the effect of regularization on synthetic feature weight (and therefore on the intercept) intercept_scaling has to be increased.
class_weightdict or ‘balanced’, default=NoneWeights associated with classes in the form {class_label: weight}. If not given, all classes are supposed to have weight one.
The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n_samples / (n_classes * np.bincount(y)).
Note that these weights will be multiplied with sample_weight (passed through the fit method) if sample_weight is specified.
Added in version 0.17: class_weight=’balanced’
random_stateint, RandomState instance, default=NoneUsed when solver == ‘sag’, ‘saga’ or ‘liblinear’ to shuffle the data. See Glossary for details.
solver{‘lbfgs’, ‘liblinear’, ‘newton-cg’, ‘newton-cholesky’, ‘sag’, ‘saga’}, default=’lbfgs’Algorithm to use in the optimization problem. Default is ‘lbfgs’. To choose a solver, you might want to consider the following aspects:
‘lbfgs’ is a good default solver because it works reasonably well for a wide class of problems.
For multiclass problems (n_classes >= 3), all solvers except ‘liblinear’ minimize the full multinomial loss, ‘liblinear’ will raise an error.
‘newton-cholesky’ is a good choice for n_samples >> n_features * n_classes, especially with one-hot encoded categorical features with rare categories. Be aware that the memory usage of this solver has a quadratic dependency on n_features * n_classes because it explicitly computes the full Hessian matrix.
For small datasets, ‘liblinear’ is a good choice, whereas ‘sag’ and ‘saga’ are faster for large ones;
‘liblinear’ can only handle binary classification by default. To apply a one-versus-rest scheme for the multiclass setting one can wrap it with the OneVsRestClassifier.
Warning
The choice of the algorithm depends on the penalty chosen (l1_ratio=0 for L2-penalty, l1_ratio=1 for L1-penalty and 0 < l1_ratio < 1 for Elastic-Net) and on (multinomial) multiclass support:
solver | l1_ratio | multinomial multiclass |
|---|---|---|
‘lbfgs’ | l1_ratio=0 | yes |
‘liblinear’ | l1_ratio=1 or l1_ratio=0 | no |
‘newton-cg’ | l1_ratio=0 | yes |
‘newton-cholesky’ | l1_ratio=0 | yes |
‘sag’ | l1_ratio=0 | yes |
‘saga’ | 0<=l1_ratio<=1 | yes |
Note
‘sag’ and ‘saga’ fast convergence is only guaranteed on features with approximately the same scale. You can preprocess the data with a scaler from sklearn.preprocessing.
See also
Refer to the User Guide for more information regarding LogisticRegression and more specifically the Table summarizing solver/penalty supports.
Added in version 0.17: Stochastic Average Gradient (SAG) descent solver. Multinomial support in version 0.18.
Added in version 0.19: SAGA solver.
Changed in version 0.22: The default solver changed from ‘liblinear’ to ‘lbfgs’ in 0.22.
Added in version 1.2: newton-cholesky solver. Multinomial support in version 1.6.
max_iterint, default=100Maximum number of iterations taken for the solvers to converge.
verboseint, default=0For the liblinear and lbfgs solvers set verbose to any positive number for verbosity.
warm_startbool, default=FalseWhen set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution. Useless for liblinear solver. See the Glossary.
Added in version 0.17: warm_start to support lbfgs, newton-cg, sag, saga solvers.
n_jobsint, default=NoneDoes not have any effect.
Deprecated since version 1.8: n_jobs is deprecated in version 1.8 and will be removed in 1.10.
Attributes: classes_ndarray of shape (n_classes, )A list of class labels known to the classifier.
coef_ndarray of shape (1, n_features) or (n_classes, n_features)Coefficient of the features in the decision function.
coef_ is of shape (1, n_features) when the given problem is binary.
intercept_ndarray of shape (1,) or (n_classes,)Intercept (a.k.a. bias) added to the decision function.
If fit_intercept is set to False, the intercept is set to zero. intercept_ is of shape (1,) when the given problem is binary.
n_features_in_intNumber of features seen during fit.
Added in version 0.24.
feature_names_in_ndarray of shape (n_features_in_,)Names of features seen during fit. Defined only when X has feature names that are all strings.
Added in version 1.0.
n_iter_ndarray of shape (1, )Actual number of iterations for all classes.
Changed in version 0.20: In SciPy <= 1.0.0 the number of lbfgs iterations may exceed max_iter. n_iter_ will now report at most max_iter.
See also
SGDClassifierIncrementally trained logistic regression (when given the parameter loss="log_loss").
LogisticRegressionCVLogistic regression with built-in cross validation.
Notes
The underlying C implementation uses a random number generator to select features when fitting the model. It is thus not uncommon, to have slightly different results for the same input data. If that happens, try with a smaller tol parameter.
Predict output may not match that of standalone liblinear in certain cases. See differences from liblinear in the narrative documentation.
References
L-BFGS-B – Software for Large-scale Bound-constrained OptimizationCiyou Zhu, Richard Byrd, Jorge Nocedal and Jose Luis Morales. http://users.iems.northwestern.edu/~nocedal/lbfgsb.html
LIBLINEAR – A Library for Large Linear Classificationhttps://www.csie.ntu.edu.tw/~cjlin/liblinear/
SAG – Mark Schmidt, Nicolas Le Roux, and Francis BachMinimizing Finite Sums with the Stochastic Average Gradient https://hal.inria.fr/hal-00860051/document
SAGA – Defazio, A., Bach F. & Lacoste-Julien S. (2014).“SAGA: A Fast Incremental Gradient Method With Support for Non-Strongly Convex Composite Objectives”
Hsiang-Fu Yu, Fang-Lan Huang, Chih-Jen Lin (2011). Dual coordinate descentmethods for logistic regression and maximum entropy models. Machine Learning 85(1-2):41-75. https://www.csie.ntu.edu.tw/~cjlin/papers/maxent_dual.pdf
Examples
>>> fromsklearn.datasetsimport load_iris >>> fromsklearn.linear_modelimport LogisticRegression >>> X, y = load_iris(return_X_y=True) >>> clf = LogisticRegression(random_state=0).fit(X, y) >>> clf.predict(X[:2, :]) array([0, 0]) >>> clf.predict_proba(X[:2, :]) array([[9.82e-01, 1.82e-02, 1.44e-08], [9.72e-01, 2.82e-02, 3.02e-08]]) >>> clf.score(X, y) 0.97For a comparison of the LogisticRegression with other classifiers see: Plot classification probability.
decision_function(X)[source]#Predict confidence scores for samples.
The confidence score for a sample is proportional to the signed distance of that sample to the hyperplane.
Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)The data matrix for which we want to get the confidence scores.
Returns: scoresndarray of shape (n_samples,) or (n_samples, n_classes)Confidence scores per (n_samples, n_classes) combination. In the binary case, confidence score for self.classes_[1] where >0 means this class would be predicted.
densify()[source]#Convert coefficient matrix to dense array format.
Converts the coef_ member (back) to a numpy.ndarray. This is the default format of coef_ and is required for fitting, so calling this method is only required on models that have previously been sparsified; otherwise, it is a no-op.
Returns: selfFitted estimator.
fit(X, y, sample_weight=None)[source]#Fit the model according to the given training data.
Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)Training vector, where n_samples is the number of samples and n_features is the number of features.
yarray-like of shape (n_samples,)Target vector relative to X.
sample_weightarray-like of shape (n_samples,) default=NoneArray of weights that are assigned to individual samples. If not provided, then each sample is given unit weight.
Added in version 0.17: sample_weight support to LogisticRegression.
Returns: selfFitted estimator.
Notes
The SAGA solver supports both float64 and float32 bit arrays.
get_metadata_routing()[source]#Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Returns: routingMetadataRequestA MetadataRequest encapsulating routing information.
get_params(deep=True)[source]#Get parameters for this estimator.
Parameters: deepbool, default=TrueIf True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns: paramsdictParameter names mapped to their values.
predict(X)[source]#Predict class labels for samples in X.
Parameters: X{array-like, sparse matrix} of shape (n_samples, n_features)The data matrix for which we want to get the predictions.
Returns: y_predndarray of shape (n_samples,)Vector containing the class labels for each sample.
predict_log_proba(X)[source]#Predict logarithm of probability estimates.
The returned estimates for all classes are ordered by the label of classes.
Parameters: Xarray-like of shape (n_samples, n_features)Vector to be scored, where n_samples is the number of samples and n_features is the number of features.
Returns: Tarray-like of shape (n_samples, n_classes)Returns the log-probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.
predict_proba(X)[source]#Probability estimates.
The returned estimates for all classes are ordered by the label of classes.
For a multiclass / multinomial problem the softmax function is used to find the predicted probability of each class.
Parameters: Xarray-like of shape (n_samples, n_features)Vector to be scored, where n_samples is the number of samples and n_features is the number of features.
Returns: Tarray-like of shape (n_samples, n_classes)Returns the probability of the sample for each class in the model, where classes are ordered as they are in self.classes_.
score(X, y, sample_weight=None)[source]#Return accuracy on provided data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
Parameters: Xarray-like of shape (n_samples, n_features)Test samples.
yarray-like of shape (n_samples,) or (n_samples, n_outputs)True labels for X.
sample_weightarray-like of shape (n_samples,), default=NoneSample weights.
Returns: scorefloatMean accuracy of self.predict(X) w.r.t. y.
set_fit_request(*, sample_weight:bool|None|str='$UNCHANGED$') → LogisticRegression[source]#Configure whether metadata should be requested to be passed to the fit method.
Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config). Please check the User Guide on how the routing mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to fit.
None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Parameters: sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for sample_weight parameter in fit.
Returns: selfobjectThe updated object.
set_params(**params)[source]#Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.
Parameters: **paramsdictEstimator parameters.
Returns: selfestimator instanceEstimator instance.
set_score_request(*, sample_weight:bool|None|str='$UNCHANGED$') → LogisticRegression[source]#Configure whether metadata should be requested to be passed to the score method.
Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config). Please check the User Guide on how the routing mechanism works.
The options for each parameter are:
True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.
False: metadata is not requested and the meta-estimator will not pass it to score.
None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.
str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.
Added in version 1.3.
Parameters: sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGEDMetadata routing for sample_weight parameter in score.
Returns: selfobjectThe updated object.
sparsify()[source]#Convert coefficient matrix to sparse format.
Converts the coef_ member to a scipy.sparse matrix, which for L1-regularized models can be much more memory- and storage-efficient than the usual numpy.ndarray representation.
The intercept_ member is not converted.
Returns: selfFitted estimator.
Notes
For non-sparse models, i.e. when there are not many zeros in coef_, this may actually increase memory usage, so use this method with care. A rule of thumb is that the number of zero elements, which can be computed with (coef_ == 0).sum(), must be more than 50% for this to provide significant benefits.
After calling this method, further fitting with the partial_fit method (if any) will not work until you call densify.
Gallery examples#
Probability Calibration curves
Probability Calibration curvesPlot classification probability
Plot classification probabilityColumn Transformer with Mixed Types
Column Transformer with Mixed TypesPipelining: chaining a PCA and a logistic regression
Pipelining: chaining a PCA and a logistic regressionFeature transformations with ensembles of trees
Feature transformations with ensembles of treesVisualizing the probabilistic predictions of a VotingClassifier
Visualizing the probabilistic predictions of a VotingClassifierRecursive feature elimination
Recursive feature eliminationRecursive feature elimination with cross-validation
Recursive feature elimination with cross-validationModel-based and sequential feature selection
Model-based and sequential feature selectionExamples of Using FrozenEstimator
Examples of Using FrozenEstimatorL1 Penalty and Sparsity in Logistic Regression
L1 Penalty and Sparsity in Logistic RegressionDecision Boundaries of Multinomial and One-vs-Rest Logistic Regression
Decision Boundaries of Multinomial and One-vs-Rest Logistic RegressionRegularization path of L1- Logistic Regression
Regularization path of L1- Logistic RegressionMulticlass sparse logistic regression on 20newgroups
Multiclass sparse logistic regression on 20newgroupsMNIST classification using multinomial logistic + L1
MNIST classification using multinomial logistic + L1Visualizations with Display Objects
Visualizations with Display ObjectsDisplaying estimators and complex pipelines
Displaying estimators and complex pipelinesDisplaying Pipelines
Displaying PipelinesIntroducing the set_output API
Introducing the set_output APIPost-tuning the decision threshold for cost-sensitive learning
Post-tuning the decision threshold for cost-sensitive learningBalance model complexity and cross-validated score
Balance model complexity and cross-validated scoreClass Likelihood Ratios to measure classification performance
Class Likelihood Ratios to measure classification performanceMulticlass Receiver Operating Characteristic (ROC)
Multiclass Receiver Operating Characteristic (ROC)Post-hoc tuning the cut-off point of decision function
Post-hoc tuning the cut-off point of decision functionMultilabel classification using a classifier chain
Multilabel classification using a classifier chainRestricted Boltzmann Machine features for digit classification
Restricted Boltzmann Machine features for digit classificationFeature discretization
Feature discretizationRelease Highlights for scikit-learn 0.22
Release Highlights for scikit-learn 0.22Release Highlights for scikit-learn 0.23
Release Highlights for scikit-learn 0.23Release Highlights for scikit-learn 0.24
Release Highlights for scikit-learn 0.24Release Highlights for scikit-learn 1.0
Release Highlights for scikit-learn 1.0Release Highlights for scikit-learn 1.1
Release Highlights for scikit-learn 1.1Release Highlights for scikit-learn 1.3
Release Highlights for scikit-learn 1.3Release Highlights for scikit-learn 1.5
Release Highlights for scikit-learn 1.5Release Highlights for scikit-learn 1.7
Release Highlights for scikit-learn 1.7Release Highlights for scikit-learn 1.8
Release Highlights for scikit-learn 1.8Classification of text documents using sparse features
Classification of text documents using sparse features On this page- LogisticRegression
- decision_function
- densify
- fit
- get_metadata_routing
- get_params
- predict
- predict_log_proba
- predict_proba
- score
- set_fit_request
- set_params
- set_score_request
- sparsify
- Gallery examples
This Page
- Show Source
Từ khóa » C=100+0 6(y-t)
-
An Introduction To C Programming For First-time Programmers
-
If An Economy (a) Consumption Function Is Given By C=100+0.75Y ...
-
YouTube
-
If In An Economy: (a) Consumption Function Is Given By C = 100 + ...
-
[PDF] C = 160 + 0.6Y I = 150 G = 150 T
-
[PDF] 14.02 Quiz 1 Solution
-
[PDF] Problem Set 2
-
[PDF] Pantone-color-chart.pdf - Upmold
-
4. Conditionals — How To Think Like A Computer Scientist
-
[PDF] Pantone-Chart.pdf - McNaughton & Gunn
-
[PDF] CHAPTER 10 MARKET POWER: MONOPOLY AND MONOPSONY
-
CIFAR-10 And CIFAR-100 Datasets