Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method BaseReferenceModel.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method BaseReferenceModel.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method BaseReferenceModel.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method BaseReferenceModel.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method ConstantModel.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method ConstantModel.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method ConstantModel.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method ConstantModel.predict
defpredict(
self,
data: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method GradientBoostingClassifier.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method GradientBoostingClassifier.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method GradientBoostingClassifier.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method LinearRegression.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method LinearRegression.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method LinearRegression.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method LinearRegression.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method LogisticRegressionClassifier.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method LogisticRegressionClassifier.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method LogisticRegressionClassifier.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method RandomForestClassifier.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method RandomForestClassifier.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method RandomForestClassifier.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method RandomForestClassifier.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method SKLearnClassifier.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method SKLearnClassifier.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method SKLearnClassifier.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method SKLearnClassifier.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's accuracy score on a data set.
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Formally it is defned as
(number of correct predictions) / (total number of preditions)
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
accuracy score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the accuracy score of predictions with optimal threshold
The accuracy score is useful to evaluate classification models. It is the fraction of the preditions that are correct. Accuracy is normally calculated under the assumption that the threshold that separates true from false is 0.5. Hovever, this is not the case when a model was trained with another population composition than on the one which is used.
This function first computes the threshold limining true from false classes that optimises the accuracy. It then returns this threshold along with the accuracy that is obtained using it.
Arguments:
data {DataFrame} -- Dataset to evaulate accuracy and accuracy threshold
Returns a tuple with:
threshold that maximizes accuracy
accuracy score obtained with this threshold
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Compute the model's binary cross entropy on the provided data.
This function is a shorthand that is equivalent to the following code:
> y_true = data[
method SKLearnRegressor.mae
defmae(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean absolute error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MAE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
method SKLearnRegressor.mse
defmse(
self,
data: pandas.core.frame.DataFrame
)
Compute the model's mean squared error on a data set.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
MSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute and plot a Confusion Matrix.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Boundary of True and False predictions, default 0.5
labels -- List of labels to index the matrix
title -- Title of the plot.
color_map -- Color map from matplotlib to use for the matrix
ax -- matplotlib axes object to draw to, default None
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plot the model's precision-recall curve.
This is a shorthand for calling feyn.plots.plot_pr_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the PR curve of the precision and recall at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
Plots the histogram of probability scores in binary
classification problems, highlighting the negative and
positive classes. Order of truth and prediction matters.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Keyword Arguments:
nbins {int} -- number of bins (default: {10})
title {str} -- plot title (default: {''})
legend {List[str]} -- legend to use on the plot for the positive and negative class (default: ["Positive Class", "Negative Class"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax {Axes} -- axes object (default: {None})
figsize {tuple} -- size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
kwargs {dict} -- histogram kwargs (default: {None})
Raises:
TypeError -- if model is not a classification model.
TypeError -- if inputs don't match the correct type.
ValueError: if y_true is not bool-like (boolean or 0/1).
ValueError: if y_pred is not bool-like (boolean or 0/1).
ValueError: if y_pred and y_true are not same size.
ValueError: If fewer than two labels are supplied for the legend.
This plots the true values on the x-axis and the predicted values on the y-axis.
On top of the plot is the line of equality y=x.
The closer the scattered values are to the line the better the predictions.
The line of best fit between y_true and y_pred is also calculated and plotted. This line should be close to the line y=x
Arguments:
data {DataFrame} -- The dataset to determine regression quality. It contains input names and output name of the model as columns
Keyword Arguments:
title {str} -- (default: {"Actuals vs Predictions"})
ax {AxesSubplot} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
This plots the predicted values against the residuals (y_true - y_pred).
Arguments:
data {DataFrame} -- The dataset containing the samples to determine the residuals of.
Keyword Arguments:
title {str} -- (default: {"Residual plot"})
ax {Axes} -- (default: {None})
figsize {tuple} -- Size of figure (default: {None})
filename {str} -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used (default: {None})
Raises:
TypeError -- if inputs don't match the correct type.
Plot the model's ROC curve.
This is a shorthand for calling feyn.plots.plot_roc_curve.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
threshold -- Plots a point on the ROC curve of the true positive rate and false positive rate at the given threshold. Default is None
title -- Title of the plot.
ax -- matplotlib axes object to draw to, default None
figsize -- size of figure when is None, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default is None
**kwargs -- additional keyword arguments to pass to Axes.plot function
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.
method SKLearnRegressor.plot_segmented_loss
defplot_segmented_loss(
self,
data: pandas.core.frame.DataFrame,
by: Optional[str]=None,
loss_function:str='squared_error',
title:str='Segmented Loss',
legend: List[str]=['Samples in bin','Mean loss for bin'],
legend_loc: Optional[str]='lower right',
ax: Optional[matplotlib.axes._axes.Axes]=None,
figsize: Optional[tuple]=None,
filename: Optional[str]=None)->None
Plot the loss by segment of a dataset.
This plot is useful to evaluate how a model performs on different subsets of the data.
Example:
> models = qlattice.sample_models(["age","smoker","heartrate"], output="heartrate")
> models = feyn.fit_models(models, data)
> best = models[0]
> feyn.plots.plot_segmented_loss(best, data, by="smoker")
This will plot a histogram of the model loss for smokers and non-smokers separately, which can help evaluate wheter the model has better performance for euther of the smoker sub-populations.
You can use any column in the dataset as the `by` parameter. If you use a numerical column, the data will be binned automatically.
Arguments:
data {DataFrame} -- The dataset to measure the loss on.
Keyword Arguments:
by -- The column in the dataset to segment by.
loss_function -- The loss function to compute for each segmnent,
title -- Title of the plot.
legend {List[str]} -- legend to use on the plot for bins and loss line (default: ["Samples in bin", "Mean loss for bin"])
legend_loc {str} -- the location (mpl style) to use for the label. If None, legend is hidden
ax -- matplotlib axes object to draw to
figsize -- Size of created figure, default None
filename -- Path to save plot. If axes is passed then only plot is saved. If no extension is given then .png is used, default None
Raises:
TypeError -- if inputs don't match the correct type.
ValueError: if by is not in data.
ValueError: If columns needed for the model are not present in the data.
ValueError: If fewer than two labels are supplied for the legend.
method SKLearnRegressor.predict
defpredict(
self,
X: Iterable
)
Get predictions for a given dataset.
Arguments:
data {Iterable} -- Data to predict for.
Returns:
Iterable -- The predictions for the data.
Compute the model's r2 score on a data set
The r2 score for a regression model is defined as
1 - rss/tss
Where rss is the residual sum of squares for the predictions, and tss is the total sum of squares.
Intutively, the tss is the resuduals of a so-called "worst" model that always predicts the mean. Therefore, the r2 score expresses how much better the predictions are than such a model.
A result of 0 means that the model is no better than a model that always predicts the mean value
A result of 1 means that the model perfectly predicts the true value
It is possible to get r2 scores below 0 if the predictions are even worse than the mean model.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
r2 score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Compute the model's root mean squared error on a data set.
Arguments:
data {DataFrame}-- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
RMSE for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
Calculate the Area Under Curve (AUC) of the ROC curve.
A ROC curve depicts the ability of a binary classifier with varying threshold.
The area under the curve (AUC) is the probability that said classifier will
attach a higher score to a random positive instance in comparison to a random
negative instance.
Arguments:
data {DataFrame} -- Data set including both input and expected values. Can be either a dict mapping register names to value arrays, or a pandas.DataFrame.
Returns:
AUC score for the predictions
Raises:
TypeError -- if inputs don't match the correct type.
TypeError -- if model is not a classification model.