https://flyte.org logo
#ask-the-community
Title
# ask-the-community
t

Taeef Najib

10/01/2022, 11:04 AM
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

Ketan (kumare3)

10/01/2022, 2:24 PM
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

Taeef Najib

10/01/2022, 8:00 PM
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

Ketan (kumare3)

10/01/2022, 11:11 PM
You can always type Hint, it will use pickle As a last resolve
t

Taeef Najib

10/02/2022, 7:34 AM
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

Ketan (kumare3)

10/02/2022, 2:32 PM
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

Taeef Najib

10/02/2022, 2:57 PM
I see! Thanks.
79 Views