'Ridge' is not a CV regularization model; try ManualAlphaSelection instead - yellowbrick

I am trying to find the best Alpha for a Ridge model without CV, using Yellowbrick ManualAlphaSelection API. My code is pretty basic and it has been taken from the yellowbrick´s documentation. Even though it does not work:
from yellowbrick.regressor import ManualAlphaSelection
from sklearn.linear_model import Ridge
model = ManualAlphaSelection(Ridge(), scoring='neg_mean_squared_error')
model.fit(X_train, y_train)
model.show()
Python raises the message: 'Ridge' is not a CV regularization model; try ManualAlphaSelection instead.
But this message is wrong because the ManualAlphaSelection is already being used.

This actually appears to be a bug in our library 😅
Would you mind opening up a bug report on GitHub so we can be sure to fix it? Thank you for checking out Yellowbrick!

Related

AttributeError: 'User' object has no attribute 'guild_permissions'

enter image description here
Hi Hello I have a question, why did I actually get this error I want to know what he actually says and I would love to get a detailed explanation.
Firstly, please provide atleast some code for context. Secondly, don't post a screenshot of the error, just include it as a codeblock in your post. That being said, my best guess from the limited information is that you need to use ctx.message.author. In your error screenshot, it seems you are just using message.author.
The guild_permissions.administrator is not exists on discord.py and that's why you getting "User" object has no attribute 'guild_permissions' error and you do not need to post a screenshot here but it's okay.
Also do you have the has_permissions?
If you do not have then
from discord.ext import commands, tasks
from discord.ext.commands import is_owner, has_permissions, MissingPermissions, BadArgument
If you do, use
#client.command()
#has_permissions(administrator=True)
async def command(ctx):
#yourscript
That's just my opinion what i was thinking.
If you're using on_message then please provide a script what you did.

google's notebook on vertex ai throwing following error: type name google.VertexModel is different from expected: Model

I got this error, when compiling my pipeline:
type name google.VertexModel is different from expected: Model
when running the following notebook by google: automl_tabular_classification_beans
I suppose that kubeflow v2 is not able to handle (yet) google.vertexmodel as type for component input. However, I've been browsing a bit and did not find any good clue, or refs (kfp documentation for v2 is not up to date..) to solve this issue. Hopefully someone here can give me a good pointer? I look forward to all of your ideas.
Cheers
Google.Vertex is defined here:
https://github.com/kubeflow/pipelines/blob/286a49547cce763c502592c822296aa60f50b3e8/components/google-cloud/google_cloud_pipeline_components/types/artifact_types.py#L20
Here is an example on how to define it:
https://github.com/kubeflow/pipelines/blob/286a49547cce763c502592c822296aa60f50b3e8/components/google-cloud/tests/types/artifact_types_test.py#L22
For example,
from google_cloud_pipeline_components.types import artifact_types
model = artifact_types.VertexModel(uri='YOUR_MODEL_URI_STRING')
Can you try specifying your model using the syntax above and let us know if this works for your code?
This was a breaking change with release 0.1.9. Here there are some recommendation:
Pin your release to 0.1.7 and continue to use the Model type.
Use 0.1.9 and switch the output from Output[Model] to Output[Artifact].
Try 0.2.0 release, documentation here.
Hope these suggestions work!

HuggingFace 'TFEmbeddings' object has no attribute 'word_embeddings'

Trying to run this TextualHeatmap example, we encounter 'TFEmbeddings' object has no attribute 'word_embeddings' error in the following code snippet from the HuggingFace transformers library. Any help is appreciated.
from transformers import TFDistilBertForMaskedLM, DistilBertTokenizer
dbert_model = TFDistilBertForMaskedLM.from_pretrained('distilbert-base-uncased')
dbert_tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-uncased')
dbert_embmat = dbert_model.distilbert.embeddings.word_embeddings
Try to use '.weight' instead of '.word_embeddings' as per hugging face latest implementation. It works for me.
Downgrading the version of transformers will work.
pip install transformers==3.1.0

LightGBM 'Using categorical_feature in Dataset.' Warning?

From my reading of the LightGBM document, one is supposed to define categorical features in the Dataset method. So I have the following code:
cats=['C1', 'C2']
d_train = lgb.Dataset(X, label=y, categorical_feature=cats)
However, I received the following error message:
/app/anaconda3/anaconda3/lib/python3.7/site-packages/lightgbm/basic.py:1243: UserWarning: Using categorical_feature in Dataset.
warnings.warn('Using categorical_feature in Dataset.')
Why did I get the warning message?
I presume that you get this warning in a call to lgb.train. This function also has argument categorical_feature, and its default value is 'auto', which means taking categorical columns from pandas.DataFrame (documentation). The warning, which is emitted at this line, indicates that, despite lgb.train has requested that categorical features be identified automatically, LightGBM will use the features specified in the dataset instead.
To avoid the warning, you can give the same argument categorical_feature to both lgb.Dataset and lgb.train. Alternatively, you can construct the dataset with categorical_feature=None and only specify the categorical features in lgb.train.
Like user andrey-popov described you can use the lgb.train's categorical_feature parameter to get rid of this warning.
Below is a simple example with some code how you could do it:
# Define categorical features
cat_feats = ['item_id', 'dept_id', 'store_id',
'cat_id', 'state_id', 'event_name_1',
'event_type_1', 'event_name_2', 'event_type_2']
...
# Define the datasets with the categorical_feature parameter
train_data = lgb.Dataset(X.loc[train_idx],
Y.loc[train_idx],
categorical_feature=cat_feats,
free_raw_data=False)
valid_data = lgb.Dataset(X.loc[valid_idx],
Y.loc[valid_idx],
categorical_feature=cat_feats,
free_raw_data=False)
# And train using the categorical_feature parameter
lgb.train(lgb_params,
train_data,
valid_sets=[valid_data],
verbose_eval=20,
categorical_feature=cat_feats,
num_boost_round=1200)
This is less of an answer to the original OP and more of an answer to people who are using sklearn API and encounter this issue.
For those of you who are using sklearn API, especially using one of the cross_val methods from sklearn, there are two solutions you could consider using.
Sklearn API solution
A solution that worked for me was to cast categorical fields into the category datatype in pandas.
If you are using pandas df, LightGBM should automatically treat those as categorical. From the documentation:
integer codes will be extracted from pandas categoricals in the
Python-package
It would make sense for this to be the equivalent in the sklearn API to setting categoricals in the Dataset object.
But keep in mind that LightGBM does not officially support virtually any of the non-core parameters for sklearn API, and they say so explicitly:
**kwargs is not supported in sklearn, it may cause unexpected issues.
Adaptive Solution
The other, more sure-fire solution to being able to use methods like cross_val_predict and such is to just create your own wrapper class that implements the core Dataset/Train under the hood but exposes a fit/predict interface for the cv methods to latch onto. That way you get the full functionality of lightGBM with only a little bit of rolling your own code.
The below sketches out what this could look like.
class LGBMSKLWrapper:
def __init__(self, categorical_variables, params):
self.categorical_variables = categorical_variables
self.params = params
self.model = None
def fit(self, X, y):
my_dataset = ltb.Dataset(X, y, categorical_feature=self.categorical_variables)
self.model = ltb.train(params=self.params, train_set=my_dataset)
def predict(self, X):
return self.model.predict(X)
The above lets you load up your parameters when you create the object, and then passes that onto train when the client calls fit.

pyLDAvis with Mallet LDA implementation : LdaMallet object has no attribute 'inference'

is it possible to plot a pyLDAvis with a Mallet implementation of LDA ? I have no troubles with LDA_Model but when I use Mallet I get :
'LdaMallet' object has no attribute 'inference'
My code :
pyLDAvis.enable_notebook()
vis = pyLDAvis.gensim.prepare(mallet_model, corpus, id2word)
vis
Run this line to convert the class of your mallet model into a LdaModel before pyLDAvis
[Edit]: edited code to use the inbuilt function in gensim instead. I just tried it but am unable to get meaningful results with the pyLDAvis on a converted mallet model; the topics seem to contain random terms.. Anybody encountered this before?
import gensim
model = gensim.models.wrappers.ldamallet.malletmodel2ldamodel(mallet_model)
Got this from the link below, do explore it, lines 565 - 590
https://github.com/RaRe-Technologies/gensim/blob/develop/gensim/models/wrappers/ldamallet.py#L359
I hope I have helped.
from gensim.models.ldamodel import LdaModel
def convertldaGenToldaMallet(mallet_model):
model_gensim = LdaModel(
id2word=mallet_model.id2word, num_topics=mallet_model.num_topics,
alpha=mallet_model.alpha, eta=0,
)
model_gensim.state.sstats[...] = mallet_model.wordtopics
model_gensim.sync_state()
return model_gensim
I found this blog post helpful, directly using the statefile produced by MALLET which is also produced using Gensim's Mallet wrapper.

Resources