In [ ]:
objective_used = skll_objective if skll_objective else 'neg_mean_squared_error'
intro_markdown_str = f"""### Characteristics 

- Model: **{model_name}**
- Number of features: **{len(features_used)}**
- Tuning objective: **{objective_used}**

if skll_fixed_parameters:
    intro_markdown_str += "- Custom fixed parameters:"
    for parameter, value in skll_fixed_parameters.items():
        intro_markdown_str += f"\n    - `{parameter}` : **{value!r}**"


In [ ]:
skll_linear_models = ['Ridge', 'BayesianRidge', 'LinearSVR', 'Lasso', 'Lars', 'HuberRegressor', 'TheilSenRegressor']

In [ ]:
weights_markdown_str = """### Feature weights

Here are the feature weights as learned by the model."""

if model_name in skll_linear_models:

In [ ]:
if model_name in skll_linear_models:

    from six import iteritems
    from skll import Learner
    from sklearn.svm import SVR
    model_file = join(output_dir, '{}.model'.format(experiment_id))
    learner = Learner.from_file(model_file)
    # get the coefficients and the intercept
    weights = {}
    coef = learner.model.coef_
    intercept = {'_intercept_': learner.model.intercept_}

    # convert SVR coefficient format (1 x matrix) to array
    if isinstance(learner._model, SVR):
        coef = coef.toarray()[0]

    # inverse transform to get indices for before feature selection
    coef = learner.feat_selector.inverse_transform(coef.reshape(1, -1))[0]
    for feat, idx in iteritems(learner.feat_vectorizer.vocabulary_):
        if coef[idx]:
            weights[feat] = coef[idx]

    # Some learners (e.g. LinearSVR) may return a list of intercepts
    if isinstance(intercept['_intercept_'], np.ndarray):
        intercept_list = ["%.12f" % i for i in intercept['_intercept_']]
        print("intercept = {}".format(intercept_list))
        print("intercept = {:.12f}".format(intercept['_intercept_']))
    print("Number of nonzero features:", len(weights))
    weight_items = iteritems(weights)
    for feat, val in sorted(weight_items, key=lambda x: -abs(x[1])):
        print("{:.12f}\t{}".format(val, feat))