0
$\begingroup$

The company I work for has a website for personal use to track leads and opportunities. I implemented a linear regression algorithm to predict a score for opportunities which is trained on the historical data of the company (I got an accuracy of about 85-90%).

Now the company would like to make their website available for other users too. I would like to know how should I train this model for multi-tenant so that it predicts based on the data of the company using it or should I train the model on a sample dataset and use that to predict for all users. Also, since in the beginning, the company will not have any data, how should I train the model?

As I am a beginner in machine learning, maybe I am missing some concepts used for this type of problem. Any resources are also welcome.

$\endgroup$
6
  • $\begingroup$ I fail to understand the objective. Can you explain what exactly is the problem with the new users? $\endgroup$
    – Nikos M.
    Jun 13, 2021 at 6:49
  • $\begingroup$ Since the model is trained on my company's data, will it work for others? I want to predict based on their data, some kind of personalized model. $\endgroup$
    – Ishaan
    Jun 13, 2021 at 6:51
  • $\begingroup$ It depends on the similarity of the users. Behavior can be similar so all is fine. Else a specialised model $\endgroup$
    – Nikos M.
    Jun 13, 2021 at 7:20
  • 1
    $\begingroup$ Just an opinion: I think it's a bad idea to provide non-tested ML predictions to non-experts third-party companies. it's likely that they will use the model incorrectly and/or interpret the results wrongly and as a result they might think that you did a bad job. Generally a supervised model is meant to predict on data which has the same distribution as the training set, so when people use different data the predictions can go horribly wrong. $\endgroup$
    – Erwan
    Jun 13, 2021 at 23:14
  • 1
    $\begingroup$ Without knowing all the context it's difficult to provide a solution, but it looks like it's a matter of designing the service properly: first, what does your company want to achieve by providing this service? How do they want it to work? What are the potential problems and how to mitigate them? It terms of solutions it ranges from just showing a warning like "this service is experimental, use it at your own risks" to providing a paid consultancy service to help customers make the best out of their data. $\endgroup$
    – Erwan
    Jun 14, 2021 at 10:24

2 Answers 2

2
$\begingroup$

Ideally you should have the historical data for your model to gain trust. However, since you don't have data you should atleast add the tenant/region feature to your model and train again.
Also keep on retraining the model, as and when failures are detected in prediction.

If different tenant users show very different behaviour then you should have different models for different tenants, as this is linear regression. Being this regression model and not deep learning, you need to do this feature engineering manually.

$\endgroup$
0
$\begingroup$

I appreciate that this response is many months late. However, I have faced the same problem and I hope that others might find this response useful.

Ishaan, one of the ways to create personalised model per company is to use Partitioned ML Model. If this approach is used, then it would look like this:

from sklearn.linear_model import LinearRegression
import pickle
import random
import numpy as np

"""
Sample data preparation for the partition.
--------
This example uses linear function y=mx+b where m is the tenant / company
specific bias and b is the error. LinearRegression is then used to find
parameters to fit the generated data.
"""
samples = 1000
x = np.random.randint(100000, size=(samples, 1))
bias =  np.random.randint(1000, size=3)
error = np.random.normal(loc=0, scale=2, size=(samples, 1))
Xy_a = np.hstack([np.full((samples,1), 0), x, bias[0]*x+error])
Xy_b = np.hstack([np.full((samples,1), 1), x, bias[1]*x+error])
Xy_c = np.hstack([np.full((samples,1), 2), x, bias[2]*x+error])
Xy = np.concatenate((Xy_a, Xy_b, Xy_c), axis=0)
random.shuffle(Xy)
X = Xy[:,0:2]
y = Xy[:,2]

"""
Example of how this model can be used.
--------
Part 1 shows how it is possible to set up, train and use Partition class with your underlying model.
Part 2 shows that model state can be preserved and reloaded for future predictions, this
  means the model should work seamlessly with MLflow.
"""
idx_to_test = np.random.randint(low=0, high=len(X), size=5).tolist()

partitioned_linear_regression = Partition(LinearRegression, normalize=True, copy_X=True)
partitioned_linear_regression.fit(X, y)
score_per_partition = partitioned_linear_regression.score(X, y)

print("Coefficient of determination per partition:", score_per_partition)

y_hat = partitioned_linear_regression.predict(X[idx_to_test])
print("y actual:", y[idx_to_test])
print("ŷ predicted:", y_hat)

filename = 'partition.pkl'
pickle.dump(partitioned_linear_regression, open(filename, 'wb'))
partitioned_linear_regression_from_pkl = pickle.load(open(filename, 'rb'))
y_hat_from_pkl = partitioned_linear_regression_from_pkl.predict(X[idx_to_test])
print("y actual:", y[idx_to_test])
print("ŷ predicted (using pkl):", y_hat_from_pkl)

After your data is trained you can save your model and use it in the future to make predictions. This can be done by using Python pickle.

You can find the whole write up and source code for this in the Medium post "Machine learning model partitioning for multi-tenant data using Python".

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.