孤立用户解决办法

解决方法:
    1.建立与孤立用户同名的登陆用户(密码随便),改变对象的属主
        sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'
    如:
         use authors
        exec sp_changeobjectowner 'authors', 'dbo';
        GO
    缺点:当需要修改的数据库对象很多时,麻烦!!
 
    2.sp_change_users_login 'Auto_Fix', 'test', NULL, 'testpassword'
      注:test为孤立用户名 testpassword为孤立用户密码
资料:
    sp_change_users_login (Transact-SQL) 将现有数据库用户映射到 SQL Server 登录名。
    注: sp_change_users_login 不能用于 Windows 主体创建的 SQL Server 登录名。

Changes the relationship between a Microsoft® SQL Server™ login and a SQL Server user in the current database.

Syntax

sp_change_users_login [@Action =] 'action' [,[@UserNamePattern =] 'user']
    [,[@LoginName =] 'login']

Arguments
[@Action =] 'action' Describes the action to be performed by the procedure. action is varchar(10), and can be one of these values.

 

Value Description Auto_Fix Links user entries in the sysusers table in the current database to logins of the same name in syslogins. It is recommended that the result from the Auto_Fix statement be checked to confirm that the links made are the intended outcome. Avoid using Auto_Fix in security-sensitive situations. Auto_Fix makes best estimates on links, possibly allowing a user more access permissions than intended.

user must be a valid user in the current database, and login must be NULL, a zero-length string (‘‘), or not specified.

Report Lists the users, and their corresponding security identifiers (SID), that are in the current database, not linked to any login.

user and login must be NULL, a zero-length string (‘‘), or not specified.

Update_One Links the specified user in the current database to login. login must already exist. user and login must be specified.
[@UserNamePattern =] 'user' Is the name of a SQL Server user in the current database. user is sysname, with a default of NULL. sp_change_users_login can only be used with the security accounts of SQL Server logins and users; it cannot be used with Microsoft Windows NT® users. [@LoginName =] 'login' Is the name of a SQL Server login. login is sysname, with a default of NULL.
Return Code Values

0 (success) or 1 (failure)

Result Sets
Column name Data type Description UserName sysname Login name. UserSID varbinary(85) Login security identifier.
Remarks

Use this procedure to link the security account for a user in the current database with a different login. If the login for a user has changed, use sp_change_users_login to link the user to the new login without losing the user’s permissions.

login cannot be sa, and user cannot be the dbo, guest, or INFORMATION_SCHEMA users.

sp_change_users_login cannot be executed within a user-defined transaction.

Permissions

Any member of the public role can execute sp_change_users_login with the Report option. Only members of the sysadmin fixed server role can specify the Auto_Fix option. Only members of the sysadmin or db_owner roles can specify the Update_One option.

Examples
A. Show a report of the current user to login mappings

This example produces a report of the users in the current database and their security identifiers.

EXEC sp_change_users_login 'Report'

  

B. Change the login for a user

This example changes the link between user Mary in the pubs database and the existing login, to the new login NewMary (added with sp_addlogin).

--Add the new login.

USE master

go

EXEC sp_addlogin 'NewMary'

go

  

--Change the user account to link with the 'NewMary' login.

USE pubs

go

EXEC sp_change_users_login 'Update_One', 'Mary', 'NewMary'


Refer:http://msdn2.microsoft.com/zh-cn/library/ms174378.aspx#

转载于:https://www.cnblogs.com/lanshh/archive/2007/02/08/644852.html

<think>好的,我现在需要帮助用户了解在孤立森林算法中如何处理仅有5个样本的情况,并设置相应的参数。首先,我得回顾孤立森林的基本原理,然后分析小样本情况下的问题,最后给出参数设置建议和实现方法。 首先,孤立森林(Isolation Forest)是一种基于树结构的异常检测算法,它通过随机选择特征和划分点来隔离样本。异常点通常更容易被隔离,因此需要的划分次数较少。正常数据点则需要更多的划分步骤。该算法使用路径长度作为异常评分的基础,路径越短,异常概率越高[^1][^3][^4]。 现在用户的问题是样本数只有5个,这明显是一个极小的数据集。通常,孤立森林适用于较大的数据集,比如scikit-learn的默认参数中,样本数下限是256(max_samples='auto'时),但用户的情况远低于这个标准。这时候需要考虑算法在小样本下的可行性和调整参数。 首先,参数设置方面: 1. max_samples:这是每个基学习器(iTree)使用的样本数。默认情况下是256,但用户只有5个样本,需要将其设置为小于等于5的值。但问题在于,当样本数过小时,每次抽样的样本可能不足以构建有效的树结构,导致模型无法正确区分异常。这时候可能需要将max_samples设为5,或者更小,比如3,但需要权衡。 2. n_estimators:树的数量。通常增加树的数量可以提高模型的稳定性,但在样本极少的情况下,增加树的数量可能作用有限,因为每个树能学习的信息很少。用户可能需要保持较低的树数量,比如10或20,但需要测试。 3. contamination:异常比例。用户需要根据实际情况估计异常的比例,但在5个样本中,异常点可能只有0或1个。如果设为'auto',可能无法正确检测,手动设置可能需要设为0.2(即假设1个异常)或更低,但需要谨慎。 4. max_features:每次划分使用的特征数。如果数据特征较多,可能需要调整,但若样本只有5个,特征数可能也少,默认值(所有特征)可能适用。 5. bootstrap:是否有放回抽样。在样本少的情况下,启用bootstrap(True)可以通过重复抽样来增加样本多样性,但需要注意过拟合的风险。 接下来,实现方法的问题。使用scikit-learn的IsolationForest时,当max_samples设置为5,但原数据只有5个样本,是否允许?需要查看文档。根据引用[5]的sklearn文档,max_samples可以是整数或小数。如果样本数小于max_samples,当bootstrap=True时,允许重复抽样,否则可能报错。因此,用户需要设置bootstrap=True,或者降低max_samples到小于等于5的值。 不过,即使参数设置正确,小样本下的模型效果可能不可靠。因为孤立森林依赖随机划分来度量异常,样本太少可能导致划分方式过于随机,无法捕捉到有效模式。例如,如果有5个样本,其中1个是异常点,可能每次划分都能很快隔离它,但由于样本量小,模型可能不够鲁棒。 可能的解决方案包括: - 增加样本量:这是最直接的解决办法,但在实际应用中可能不可行。 - 调整参数:如上述参数设置,但需谨慎验证。 - 使用其他方法:对于极小的样本,可能需要使用基于统计的方法或单类分类(如One-Class SVM)等更适合小数据集的算法。 最后,需要提醒用户在小样本情况下结果的可靠性问题,并建议结合领域知识或其他方法验证结果。</think>### 孤立森林在5个样本场景下的实现与参数设置 #### 核心参数调整建议 1. **`max_samples`** - **强制设置为5**:`max_samples=5`(必须显式指定,禁用`auto`模式) - **启用有放回抽样**:`bootstrap=True`(避免因样本不足导致报错)[^5] 2. **`n_estimators`** - **减少树的数量**:建议设置为`10-50`(默认100会因样本过少产生冗余计算) 3. **`contamination`** - **手动指定异常比例**:若明确知道异常数量,例如1个异常点则设为`contamination=0.2`[^3] 4. **`max_features`** - **特征数较少时**:保持默认`max_features=1.0`(使用全部特征划分) #### 实现代码示例 ```python from sklearn.ensemble import IsolationForest X = [[0], [1], [2], [3], [10]] # 示例数据(假设第5个点为异常) model = IsolationForest( max_samples=5, # 强制使用全部5个样本 bootstrap=True, # 允许有放回抽样 n_estimators=10, # 减少树的数量 contamination=0.2, # 假设异常比例为20% random_state=42 ) model.fit(X) print(model.predict(X)) # 输出预测结果(-1表示异常) ``` #### 局限性说明 1. **模型可靠性低**: 5个样本难以形成有效划分空间,异常评分可能随机波动[^1][^4] 2. **理论依据薄弱**: 孤立森林依赖大量样本的路径长度分布归一化(公式:$$c(n) = 2H(n-1) - \frac{2(n-1)}{n}$$),小样本无法准确计算$H(n)$调和数[^3] 3. **建议替代方案**: - 3σ准则(当数据近似正态分布时) - 箱线图法(检测四分位距外的离群点) - 单类SVM(One-Class SVM)[^2] #### 验证方法 ```python # 查看样本路径长度(值越小越异常) print(model.decision_function(X)) ``` 输出值接近`-0.5`表示异常,接近`0.5`表示正常
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值