Hi, team, I’m aware of the fact that Flytekit auto...
# ask-the-community
t
Hi, team, I’m aware of the fact that Flytekit automatically converts Python type hint into Flyte type hint.
Copy code
# Creating the Multiple Linear Regression model
def build_model(model, X_train: pd.DataFrame, y_train: pd.DataFrame):
    # Use the following values: model = LinearRegression(), X_train = X_train, y_train =    y_train
    reg = model
    reg.fit(X_train, y_train)
    return reg
I’m using
int
,
float
,
pd.DataFrame
,
np.ndarray
etc. as my type hints. My question is what type hint do I use for the argument
model
and since it is returning the model, what type hint should I use for
reg
?
k
If you simply return the model, that’s ok it will be pickled
If you want it to be portable- use joblib etc
Or you can contribute a transformer for sculpt learn models
Cc @Samhita Alla great hacktoberfest stories
t
Hi, @Ketan (kumare3) does that mean Flyte will not have issues if I don’t add any type hint to the model? I thought type hinting is a pre-requisite for Flyte to work. Also, if I have to use a type hint, can I use the following?
Copy code
from sklearn.base import RegressorMixin

def build_model(model: RegressorMixin, X_train: pd.DataFrame, y_train: pd.DataFrame) -> RegressorMixin:
    # Use the following values: model = LinearRegression(), X_train = X_train, y_train =    y_train
    reg = model
    reg.fit(X_train, y_train)
    return reg
Since all regression models inherit from
sklearn.base.RegressorMixin
Can we do this?
k
You can always type Hint, it will use pickle As a last resolve
t
But what about other arguments like int, float, pd.DataFrame, etc. If I don’t use those, will Flyte show me any error?
Thanks for your help Ketan
k
No you always have to use type hints
This helps Flyte analyze and convert
If a plugin is found that is used, else, pickled
t
I see! Thanks.
156 Views